【发布时间】:2013-01-22 01:15:45
【问题描述】:
我关注 this example 为我的切换按钮应用了一些自定义主题,但是当我运行我的应用程序时,我看到了通用的 android 切换图标 - 我想我在这里或那里缺少一个设置,可以使用一组额外的盯着它。
我有一个在 ListView 中使用的布局,我正在尝试将自定义可绘制对象用于选中/未选中状态,每个切换状态默认设置为 CHECKED:
<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 目录中:
<?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>
我已经验证了自定义图像存在于 drawables 目录中,所以显然要么我误解了样式级联方式的某些内容,要么我在这种疯狂的样式中遗漏了某处的参考。
【问题讨论】:
标签: android android-listview android-button