Created
April 5, 2012 02:15
-
-
Save kimukou/2307476 to your computer and use it in GitHub Desktop.
Android ボタンのちょっとしたスタイルの編集メモ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* 一つのボタンを押している時に、他のボタンをsetEnable(false)する。 | |
その時に色を変えたくない | |
1) | |
android-sdks/platforms/android-15/data/res/drawable | |
btn_default.xml | |
android-sdks/platforms/android-15/data/res/drawable-hdpi | |
btn_default.xml で使用しているリソースをコピー。 | |
ただし .9.png という名前で存在している(そのまま持ってこればOK | |
2) | |
drawableに上記のデータをコピー(btn_layout.xmlと名前を変えました) | |
下記のように編集 | |
(記述されているアクションは一通り無いとエラーになる<部分的selecterの指定は難しい) | |
3)プログラム上からは | |
b_One.setBackgroundResource( R.drawable.btn_style ); | |
b_Two.setBackgroundResource( R.drawable.btn_style ); | |
b_Three.setBackgroundResource( R.drawable.btn_style ); | |
と指定 | |
ただボタンの高さが、スタイル適応時に変にリサイズされるみたいなので | |
ボタンを配置しているのLinerLayout等で android:layout_height="50dp" 等の指定が必要かも | |
--------------------------------------------------- | |
現状の問題点) | |
* リソース分サイズが大きくなる | |
* ボタン押したとき黄色になる<普通は青? | |
* 高さのサイズがへん(手動で指定しないと。WCだとフィットしない。。setTextSize(12.0f) とかもだめ。。 | |
final int WC = ViewGroup.LayoutParams.WRAP_CONTENT; | |
final int FP = ViewGroup.LayoutParams.FILL_PARENT; | |
WindowManager windowManager = getWindowManager(); | |
Display display = windowManager.getDefaultDisplay(); | |
final DisplayMetrics displayMetrics = new DisplayMetrics(); | |
display.getMetrics(displayMetrics); | |
m_heightPixels = displayMetrics.heightPixels; | |
int h = m_heightPixels /10; | |
LinearLayout l | |
l.addView(b_One, new LinearLayout.LayoutParams(FP, h, 1)); | |
あたりが妥当? | |
--------------------------------------------------- | |
カスタムボタンの情報) | |
http://android.migimaki.com/tag/button |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item android:state_window_focused="false" android:state_enabled="true" | |
android:drawable="@drawable/btn_default_normal" /> | |
<!-- | |
<item android:state_window_focused="false" android:state_enabled="false" | |
android:drawable="@drawable/btn_default_normal_disable" /> | |
--> | |
<item android:state_window_focused="false" android:state_enabled="false" | |
android:drawable="@drawable/btn_default_normal" /> | |
<item android:state_pressed="true" | |
android:drawable="@drawable/btn_default_pressed" /> | |
<item android:state_focused="true" android:state_enabled="true" | |
android:drawable="@drawable/btn_default_selected" /> | |
<item android:state_enabled="true" | |
android:drawable="@drawable/btn_default_normal" /> | |
<item android:state_focused="true" | |
android:drawable="@drawable/btn_default_normal_disable_focused" /> | |
<!-- | |
<item | |
android:drawable="@drawable/btn_default_normal_disable" /> | |
--> | |
<item | |
android:drawable="@drawable/btn_default_normal" /> | |
</selector> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment