自定义搜索栏与材质设计 [英] Custom seekbar with material design

查看:111
本文介绍了自定义搜索栏与材质设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在一个自定义对话框preference布局中的搜索栏。我改变了我的styles.xml使用新材料德兴。它的工作原理是因为它改变的文字和我的设置复选框,但我不能颜色适用于我的搜索栏。它的工作原理只有当我把一个搜索栏一个活动,这意味着我必须做的东西在我的自定义布局,但我不知道是什么。我张贴styles.xml和搜索栏的布局:

 <?XML版本=1.0编码=UTF-8&GT?;
<资源>    <样式名称=AppBaseTheme父=机器人:Theme.Material>        <! - 主要主题颜色 - >
        <! - 你的应用的品牌颜色(应用栏) - GT;
        <项目名称=机器人:colorPrimary>#FFFF4444< /项目>
        <! - colorPrimary(为状态栏,上下文应用栏)的暗变种 - >
        <项目名称=机器人:colorPrimaryDark>#FFCC0000< /项目>
        <! - 像复选框和文本字段主题UI控件 - >
        <项目名称=机器人:colorAccent>#FFFF00< /项目>
    < /风格>    <! - 应用的主题。 - >
    <样式名称=AppTheme父=AppBaseTheme>
    < /风格>< /资源>

有关对话preference自定义布局:

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=垂直>    <搜索栏
        机器人:ID =@ + ID / seek_bar
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_marginBottom =6DIP
        机器人:主题=@安卓风格/ Theme.Material
        机器人:layout_marginTop =6DIP/>< / LinearLayout中>


解决方案

您不需要指定的android:你的搜索栏元素的主题属性。相反,你应该设置默认对话框,并在您AppBaseTheme提醒对话框主题:

 <样式名称=AppBaseTheme父=机器人:Theme.Material>
    ...
    <项目名称=机器人:dialogTheme> @风格/ AppDialogTheme< /项目>
    <项目名称=机器人:alertDialogTheme> @风格/ AppAlertTheme< /项目>
< /风格><样式名称=AppDialogTheme父=机器人:Theme.Material.Dialog>
    <项目名称=机器人:colorPrimary>#FFFF4444< /项目>
    <项目名称=机器人:colorPrimaryDark>#FFCC0000< /项目>
    <项目名称=机器人:colorAccent>#FFFF00< /项目>
< /风格><! - 这应该延长Theme.Material.Dialog.Alert,但风格是
     不正确地隐藏在L- preVIEW。这将是固定在未来的版本。
     您可以使用最后两个了minWidth属性近似风格.-->
<样式名称=AppAlertTheme父=机器人:Theme.Material.Dialog>
    <项目名称=机器人:colorPrimary>#FFFF4444< /项目>
    <项目名称=机器人:colorPrimaryDark>#FFCC0000< /项目>
    <项目名称=机器人:colorAccent>#FFFF00< /项目>
    <项目名称=机器人:windowMinWidthMajor并在65%LT; /项目>
    <项目名称=机器人:windowMinWidthMinor> 95%LT; /项目>
< /风格>

I've got a seekbar in a layout for a custom dialog preference. I changed my styles.xml to use the new material desing. It works because it change text and checkboxes of my settings but I can't apply the color to my seekbar. It works only if I put a seekbar in an activity, it means I have to do something in my custom layout but I don't know what. I post styles.xml and the layout with the seekbar:

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

custom layout for dialog preference:

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

解决方案

You don't need to specify the android:theme attribute on your SeekBar element. Instead, you should set up the default dialog and alert dialog themes in your 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>

这篇关于自定义搜索栏与材质设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆