android - 具有 Material 设计的自定义搜索栏

标签 android material-design

我在布局中有一个用于自定义对话框首选项的搜索栏。我更改了 styles.xml 以使用新 Material 设计。它之所以有效,是因为它更改了我的设置的文本和复选框,但我无法将颜色应用到我的搜索栏。只有当我在 Activity 中放置搜索栏时它才有效,这意味着我必须在我的自定义布局中做一些事情但我不知道是什么。我发布 styles.xml 和带有搜索栏的布局:

<?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>

对话框首选项的自定义布局:

<?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>

最佳答案

With Lollipop it's no more needed at all. The colors are applied well even in custom preference dialogs ~greywolf82

我想分享一些自定义库

enter image description here

你可以使用这个 Material Design lib ,这还包括许多其他小部件。

enter image description here

自定义搜索栏库 DiscreteSeekBar

关于android - 具有 Material 设计的自定义搜索栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24476072/

相关文章:

java - Activity/fragment 转换是否与 Lollipop 之前的设备兼容?

android - 共享元素到 ImageView 的转换在退出时有效,但在进入时不平滑

android - 带有文本选择控件的 float 工具栏

Android 4.4.3 WebView 不再遵循重定向

android - 在后台访问 Google Drive Android API

android - 如何在 Android Espresso 中检查文本字体样式

android - Material Design 和 appcompat 不适用于较旧的 API 版本

Android:如何在 ListView 中添加静态行

android - View 翻转器 : OutOfMemoryError: bitmap size exceeds VM budget

android - 如何在不重复的情况下更改 MaterialButton 的样式?