출처:http://blog.naver.com/PostView.nhn?blogId=ezmo01&logNo=110093890027&viewDate=¤tPage=1&listtype=0&userTopListOpen=false&userTopListCount=5&userTopListManageOpen=false&userTopListCurrentPage=undefined
Custom Android Button Style and Theme
Posted by Tonio | Filed under Tutorial
In this tutorial, we’ll see how it’s possible to create a custom button style for an Android application by using the Android styling API. First of all we need to define the new look for our custom button style. We would use three different NinePatch drawables.
A custom black nine patch drawable background for enabled, not pressed buttons :
A custom orange nine patch drawable background for enabled, pressed buttons :
A custom red nine patch drawable background for disabled buttons :
All of these three custom drawable must be placed in the /res/drawables directory of our Android application. Now we must declare wich background should be used for each possible state of our custom button (pressed, disabled, focused, …). This is done by declaring a selector in a custom XML file :
2.2기준으로 아래 파일은 res/xml-hdpi/btn_custom.xml에 위치해야함.
Each item in the selector associates a drawable to a button state. Items must be declared in a specific order. The android selector draws the first selector item that match the current button state, no matter if another matching item is defined in the selector declaration. For exemple, the selector bellow will never draw the orange background for a disabled and focused button as the first item always applies to disabled button :
여긴 필요없음
In order to draw orange background for disabled and focused buttons, and a red background for disabled buttons that are not focused we should have invert the items declaration order :
여기도 필요없음
Let’s put our selector declaration in a file called btn_custom.xml in the /res/drawables directory of our Android application. Now, it’s time to define a custom button style that will apply to every buttons in the application. This can be achieve with both the /res/values/styles.xml file and the /res/values/themes.xml file. In the first one we’ll customize our button appearence (selector, text size, text color, shadow, …).
/res/values/styles.xml 에 위치함 중요한건 아래
name="android:background">@drawable/btn_custom</item> <item 을...
> @xml/btn_custom 으로 바꿔야한다.. 2.2에서 좀 바뀐거 같음.
Then, we must set this style to be used by the Android button Widget. In the /res/values/themes.xml file :
/res/values/themes.xml 기본파일이 없는지 이해가 안되지만... 만들어주자..
The theme can be applied to the whole application by setting the android:theme attribute in the<application> tag of the AndroidManifest.xml file.
여긴 써있는데로 메니페스트에서 변경하고...
Now, that’s what your buttons looks like :
You can browse the full source code of the Eclipse project here :
SampleCustomButton
'Android > Tip&Tech' 카테고리의 다른 글
웹뷰 키보드 위치조절(webview) (0) | 2011.11.29 |
---|---|
SQL function(함수) 모음 (2) | 2011.11.23 |
Android PopupWindow 관련 팁 (0) | 2011.11.23 |
[펌]Android Traceview War Story (0) | 2011.11.22 |
android honeycomb 최적화하기 (0) | 2011.11.21 |