我正在使用PreferenceFragment通过一个SwitchPreference对一个xml文件进行充气。我如何制作该首选项的背景颜色,包括SwitchPreference的标题以匹配下面的图像。我已经尝试设置背景,但我只能设置开关图标的背景颜色。如何将背景颜色添加到Android SwitchPreference?
1
A
回答
0
我使用样式
Style.xml
<style name="SwitchTheme" parent="Theme.AppCompat.Light">
<item name="colorControlActivated">@color/yourcolor</item>
</style>
在布局
<android.support.v7.widget.SwitchCompat
android:id="@+id/switch_on_off"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="center"
android:checked="false"
android:gravity="center"
android:paddingLeft="@dimen/padding"
android:paddingRight="@dimen/padding"
app:switchMinWidth="@dimen/switch_size"
app:theme="@style/SwitchTheme" />
0
styles.xml做到了这一点(做这种风格在style.xml文件在值文件夹中)
<resources>
<style name="SwitchTheme" parent="Theme.AppCompat.Light">
<!-- switch on thumb & track color -->
<item name="colorControlActivated">#02c754</item>
<!-- switch off thumb color -->
<item name="colorSwitchThumbNormal">#f1f1f1</item>
<!-- switch off track color -->
<item name="android:colorForeground">#42221f1f</item>
</style>
</resources>
your_layout_activity.xml
<android.support.v7.widget.SwitchCompat
android:id="@+id/switch_on_off"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="center"
android:checked="true"
android:gravity="center"
android:paddingLeft="30dp"
android:theme="@style/SwitchTheme"
app:switchMinWidth="55dp"/>
这个源为我工作。试试这个,你会明白
相关问题
- 1. 将背景图像和背景颜色对添加到元素
- 2. 背景颜色不添加
- 3. 使用switchpreference设置颜色背景的Android
- 4. 如何为BarButton添加背景颜色
- 5. 如何将纹理类型外观添加到背景颜色
- 6. 如何将背景颜色添加到HTML选项?
- 7. 添加PNG和颜色到背景
- 8. 将背景图像叠加到背景颜色上
- 9. 如何背景颜色添加到所选元素
- 10. 我如何添加颜色,背景或动画到ListView
- 11. 如何阻止背景颜色被添加到BottomNavigationView
- 12. 如何渐变颜色添加到背景DIV
- 13. 使用sed将标签添加到背景颜色?
- 14. 将行添加到表中并更改其背景颜色
- 15. 将文本背景颜色添加到JTable列
- 16. 将背景颜色添加到KML文件中的多边形
- 17. iTextSharp将背景颜色添加到水印文本
- 18. Android RelativeLayout背景颜色
- 19. 如何改变背景颜色和背景颜色?
- 20. 如何为同一元素添加叠加颜色和背景颜色
- 21. 如何添加背景到android webview?
- 22. 如何将背景颜色添加到IKImageBrowserCell的标题标签中?
- 23. 如何将背景颜色添加到居中文本的宽度?
- 24. 如何将一个类添加到div以更改背景颜色?
- 25. 颜色背景
- 26. Android - 将imageView添加到背景
- 27. Android获取父视图的背景颜色,如果没有背景颜色集
- 28. 将颜色添加到颜色数组
- 29. 如何在将背景图像剪切到文本时为背景添加颜色?
- 30. 如何在PHP中为ODD和EVEN行添加背景颜色?
https://stackoverflow.com/questions/21235829/custom-switchpreference-in-android/21854548 –
我期待改变整个背景,包括文字背后的颜色 –