本文介绍了如何设置棒棒糖开关按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为我的应用设置棒棒糖样式切换按钮:
I want to have the Lollipop style switch button for my app:
我该如何实现此按钮,使其在旧版android上也是如此?
How could I implement this button so it looks like this also on older versions of android?
推荐答案
首先在清单中设置 android:targetSdkVersion = 22
以使您的应用兼容到棒棒糖。
At first set android:targetSdkVersion="22"
in your manifest to make your app compatible to Lollipop.
注意:开关的颜色取决于此
<item name="android:colorAccent">@color/accent</item>
使用
styles.xml 为应用创建自己的主题>在文件夹 values-v21
Create your own theme for your app instyles.xml in Folder values-v21
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:colorPrimary">@color/primary</item>
<item name="android:colorPrimaryDark">@color/primary_dark</item>
<item name="android:colorAccent">@color/accent</item>
<item name="android:textColorPrimary">@color/text_primary</item>
<item name="android:textColor">@color/text_secondary</item>
<item name="android:navigationBarColor">@color/primary_dark</item>
<item name="toolbarStyle">@style/Widget.AppCompat.Toolbar</item>
</style>
</resources>
styles.xml 在默认文件夹值中或 values-v14
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">
<!-- Customize your theme here. -->
<item name="toolbarStyle">@style/Widget.AppCompat.Toolbar</item>
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">@color/primary</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">@color/primary_dark</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">@color/accent</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight & colorSwitchThumbNormal. -->
</style>
</resources>
这篇关于如何设置棒棒糖开关按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!