Button图标和文字位置设置技巧。一般情况下足用,特殊情况例外
<style name="btn_menu">
<item name="android:background">@color/transparent</item>
<item name="android:layout_width">80dp</item>
<item name="android:layout_height">80dp</item>
<item name="android:textColor">@drawable/selector_menu_txt_click</item>
<item name="android:paddingTop">15dp</item>
<item name="android:drawablePadding">-13dp</item>
<item name="android:textSize">12sp</item>
</style>
单次点击选中效果不消失,再次点击回复
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 点击后 -->
<item android:color="@color/white"
android:state_activated="true" />
<!-- 未点击或再次点击之后的color -->
<item android:color="@color/c999999"
android:state_activated="false" />
</selector>
代码设置
btn.setActivated (boolean);
一般背景点击效果
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@mipmap/menu_tianditu_pressed" android:state_enabled="true" android:state_focused="true" android:state_pressed="false" />
<item android:drawable="@mipmap/menu_tianditu_pressed" android:state_enabled="true" android:state_pressed="true" />
<item android:drawable="@mipmap/menu_tianditu_pressed" android:state_checked="true" android:state_enabled="true" />
<item android:drawable="@mipmap/menu_tianditu_normal" />
</selector>
一般文字点击效果
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/white" android:state_selected="true"/>
<item android:color="@color/white" android:state_pressed="true"/>
<item android:color="@color/c999999"/>
</selector>