我跟着这个例子 http://www.mokasocial.com/2011/07/sexily-styled-toggle-buttons-for-android/用于将一些自定义主题应用于我的切换按钮,但是当我运行我的应用程序时,我看到通用的 android 切换图标 - 我认为我在这里或那里缺少一个设置,并且可以使用额外的眼睛来观察它。
我有一个用于使用的布局ListView
为此,我尝试将自定义可绘制对象用于选中/未选中状态,每个切换状态默认设置为“已检查”:
<ToggleButton
android:id="@+id/profile_item_value_text"
style="@style/ProfileTagTheme"
android:layout_width="0px"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textSize="16dp"
android:textColor="@color/black"
android:layout_gravity="center"
android:gravity="center_vertical|center_horizontal"
android:checked="true" />
这是我的styles
归档ProfileTagTheme
:
<style name="Widget.Button.Toggle" parent="android:Widget">
<item name="android:background">@drawable/profile_btn_toggle_bg</item>
<item name="android:disabledAlpha">@android:attr/disabledAlpha</item>
</style>
<style name="ProfileTagTheme" parent="android:Theme.Black">
<item name="android:buttonStyleToggle">@style/Widget.Button.Toggle</item>
</style>
反过来,profile_btn_toggle_bg.xml
,住在我的主要drawable
dir:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background" android:drawable="@android:color/transparent"/>
<item android:id="@android:id/toggle" android:drawable="@drawable/profile_btn_toggle"/>
</layer-list>
哪些参考文献profile_btn_toggle
,就在它旁边:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/tag_active" /> <!-- pressed -->
<item android:drawable="@drawable/tag" /> <!-- default/unchecked -->
</selector>
我已经验证了自定义图像存在于可绘制目录中,因此显然要么我误解了样式级联的方式,要么我在这种疯狂的样式中缺少了某个参考。