Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未应用Android ToggleButton自定义样式_Android_Android Listview_Android Button - Fatal编程技术网

未应用Android ToggleButton自定义样式

未应用Android ToggleButton自定义样式,android,android-listview,android-button,Android,Android Listview,Android Button,我在我的切换按钮上应用了一些自定义主题,但当我运行我的应用程序时,我看到了通用的android切换图标——我想我在这里或那里缺少一个设置,可能需要额外的一组眼睛 我在列表视图中使用了一个布局,我试图为其使用选中/未选中状态的自定义绘图,每个切换状态默认设置为选中: <ToggleButton android:id="@+id/profile_item_value_text" style="@style/ProfileTagTheme" and

我在我的切换按钮上应用了一些自定义主题,但当我运行我的应用程序时,我看到了通用的android切换图标——我想我在这里或那里缺少一个设置,可能需要额外的一组眼睛

我在
列表视图
中使用了一个布局,我试图为其使用选中/未选中状态的自定义绘图,每个切换状态默认设置为选中:

<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" />
反过来,
profile\u btn\u toggle\u 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>

我已经验证了drawables目录中存在自定义图像,因此很明显,要么我对样式层叠的方式有误解,要么我在这种样式疯狂中遗漏了一个参考

在我的几个应用程序中,我都会这样做。请记住,这是一种完全不同的风格,可能/可能不适合您的情况。通过设置背景,我可以设置切换按钮所需的图像:

<ToggleButton
    android:id="@+id/tb_useNotificationShortcuts"
    android:layout_width="100dp"
    android:layout_height="25dp"
    android:layout_gravity="center"
    android:background="@drawable/togglebutton"
    android:tag="21" />


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

   <item android:drawable="@drawable/custom_toggle_on" android:state_checked="true"/>
   <!-- pressed -->
   <item android:drawable="@drawable/custom_toggle_off"/>
   <!-- default/unchecked -->

</selector>


“自定义切换打开”和“自定义切换关闭”是我的图像,它们也可以是你的图层列表。

我在我的一些应用程序中执行类似操作。请记住,这是一种完全不同的风格,可能/可能不适合您的情况。通过设置背景,我可以设置切换按钮所需的图像:

<ToggleButton
    android:id="@+id/tb_useNotificationShortcuts"
    android:layout_width="100dp"
    android:layout_height="25dp"
    android:layout_gravity="center"
    android:background="@drawable/togglebutton"
    android:tag="21" />


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

   <item android:drawable="@drawable/custom_toggle_on" android:state_checked="true"/>
   <!-- pressed -->
   <item android:drawable="@drawable/custom_toggle_off"/>
   <!-- default/unchecked -->

</selector>


“自定义切换”和“自定义切换”是我的图像,它们也可能是你的图层列表。

因此,我唯一的真正问题似乎是缺少我的
切换按钮实现中的
android:background
元素;因此,对上面代码的唯一更改是添加该元素,例如

<ToggleButton
        android:id="@+id/profile_item_value_text"
        style="@style/ProfileTagTheme"
        android:background="@drawable/profile_btn_toggle_bg"
        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"
        android:onClick="onToggleClicked" />

所以我唯一真正的问题似乎是在我的
切换按钮
实现中缺少了
android:background
元素;因此,对上面代码的唯一更改是添加该元素,例如

<ToggleButton
        android:id="@+id/profile_item_value_text"
        style="@style/ProfileTagTheme"
        android:background="@drawable/profile_btn_toggle_bg"
        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"
        android:onClick="onToggleClicked" />