Custom Views in the application (Android)

做~自己de王妃 提交于 2019-12-06 21:01:27

The answer is to use a theme as you were expecting. Good documentation can be found on android developer site: http://developer.android.com/guide/topics/ui/themes.html

For the button you can do like this: Define a new theme:

<style name="MyTheme" parent="@android:style/Theme.Holo">
    <item name="android:buttonStyle">@style/button</item>
</style>

Where the button style is defined as:

<style name="button" parent="@android:style/Widget.Button">
    <item name="android:background">@drawable/button_background_selector</item>
    <item name="android:textColor">@drawable/button_text_selector</item>
</style>

The button_background_selector is defined like this:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/button_pressed" android:state_pressed="true"></item>
    <item android:drawable="@drawable/button_disabled" android:state_enabled="false"></item>
    <item android:drawable="@drawable/button_default"></item>

</selector>

All those drawables can be your images - button_pressed can be a png in the drawable folders. You also have to apply the theme to your application in the manifest like this:

<application
    android:theme="@style/MyTheme" >
</application>

Hope this helps :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!