Android 带材质设计的定制seekbar
我在布局中有一个seekbar,用于自定义对话框首选项。我更改了styles.xml以使用新材料设计。它之所以有效,是因为它会更改我设置的文本和复选框,但我无法将颜色应用于我的seekbar。只有当我在活动中放置一个seekbar时,它才起作用,这意味着我必须在我的自定义布局中做一些事情,但我不知道做什么。我用seekbar发布styles.xml和布局:Android 带材质设计的定制seekbar,android,material-design,Android,Material Design,我在布局中有一个seekbar,用于自定义对话框首选项。我更改了styles.xml以使用新材料设计。它之所以有效,是因为它会更改我设置的文本和复选框,但我无法将颜色应用于我的seekbar。只有当我在活动中放置一个seekbar时,它才起作用,这意味着我必须在我的自定义布局中做一些事情,但我不知道做什么。我用seekbar发布styles.xml和布局: <?xml version="1.0" encoding="utf-8"?> <resources> &l
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppBaseTheme" parent="android:Theme.Material">
<!-- Main theme colors -->
<!-- your app's branding color (for the app bar) -->
<item name="android:colorPrimary">#FFFF4444</item>
<!-- darker variant of colorPrimary (for status bar, contextual app bars) -->
<item name="android:colorPrimaryDark">#FFCC0000</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">#FFFF00</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
</style>
</resources>
#FF4444
#FFCC0000
#FFFF00
对话框首选项的自定义布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<SeekBar
android:id="@+id/seek_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dip"
android:theme="@android:style/Theme.Material"
android:layout_marginTop="6dip" />
</LinearLayout>
您不需要在SeekBar元素上指定android:theme属性。相反,您应该在AppBaseTheme中设置默认对话框和警报对话框主题:
<style name="AppBaseTheme" parent="android:Theme.Material">
...
<item name="android:dialogTheme">@style/AppDialogTheme</item>
<item name="android:alertDialogTheme">@style/AppAlertTheme</item>
</style>
<style name="AppDialogTheme" parent="android:Theme.Material.Dialog">
<item name="android:colorPrimary">#FFFF4444</item>
<item name="android:colorPrimaryDark">#FFCC0000</item>
<item name="android:colorAccent">#FFFF00</item>
</style>
<!-- This should extend Theme.Material.Dialog.Alert, but that style was
incorrectly hidden in L-preview. It will be fixed in a future release.
You can approximate the style using the last two MinWidth attributes.-->
<style name="AppAlertTheme" parent="android:Theme.Material.Dialog">
<item name="android:colorPrimary">#FFFF4444</item>
<item name="android:colorPrimaryDark">#FFCC0000</item>
<item name="android:colorAccent">#FFFF00</item>
<item name="android:windowMinWidthMajor">65%</item>
<item name="android:windowMinWidthMinor">95%</item>
</style>
...
@样式/应用对话框主题
@风格/AppAlertTheme
#FF4444
#FFCC0000
#FFFF00
#FF4444
#FFCC0000
#FFFF00
65%
95%
有了棒棒糖,就不再需要它了。颜色运用得很好 甚至在自定义首选项对话框~greywolf82中 我想分享一些自定义库 您可以使用这个,它还包括许多其他小部件 或
自定义搜索栏库您知道即使对于holo也可能有类似的功能吗?colorAccent是一个重要项目,我找不到holo的任何东西。谢谢。您可以通过在drawable上设置PorterDuffColorFilter(请参见drawable.setColorFilter)以编程方式完成此操作,但不能从XML进行。您刚刚尝试了您的解决方案,但根本不起作用。Material.Dialog.Alert不存在。所有与我的seekbar对话仍然使用蓝色全息图。我认为问题在于对话框首选项,它使用默认的AlertDialog构造函数,但没有指定主题,在这种情况下,覆盖根本不起作用。对不起,你完全正确,这是对话框首选项中的一个错误。它已在内部修复,但在lmp预览版本中被破坏。与警报对话框主题相同。是否可以共享链接以查看内部修复?只是好奇:)有了棒棒糖就不需要了。即使在自定义首选项对话框中,颜色也能很好地应用。@greywolf82您的意思是新的Appcompat库可以做到这一点吗?看看高达2.3的支持?是的,即使Appcompat支持有限,但使用棒棒糖就像一种魅力。