我们要修改一下button,修改一下按下去的效果
最必要的就是修改
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_enabled="false"
android:drawable="@drawable/btn_red" />
<item
android:state_pressed="true"
android:state_enabled="true"
android:drawable="@drawable/btn_orange" />
<item
android:state_focused="true"
android:state_enabled="true"
android:drawable="@drawable/btn_orange" />
<item
android:state_enabled="true"
android:drawable="@drawable/btn_black" />
</selector>
上面的代码适合所有按钮的配置 只要修改就可以了
命名为/res/drawables /btn_custom,
然后修改一下样式
/res/values/styles.xml
<resources>
<style name="Button" parent="@android:style/Widget.Button">
<item name="android:gravity">center_vertical|center_horizontal</item>
<item name="android:textColor">#FFFFFFFF</item>
<item name="android:shadowColor">#FF000000</item>
<item name="android:shadowDx">0</item>
<item name="android:shadowDy">-1</item>
<item name="android:shadowRadius">0.2</item>
<item name="android:textSize">16dip</item>
<item name="android:textStyle">bold</item>
<item name="android:background">@drawable/btn_custom</item>
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
</style>
</resources>
为了将整个程序的button都改为一个 修改主题
/res/values/themes.xml
<resources>
<style name="CustomButton" parent="android:style/Theme.NoTitleBar">
<item name="android:buttonStyle">@style/Button</item>
</style>
</resources>
<application android:icon="@drawable/icon"
android:label="Custom button"
android:theme="@style/CustomButton">