Android设置主题全局编辑文本样式不起作用 [英] Android set edit text style globally in theme doesn't work

查看:390
本文介绍了Android设置主题全局编辑文本样式不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正面临问题.我正在尝试借助主题使我的应用程序中的编辑文本看起来相同.
我借助在线工具(9个补丁图像)生成了样式,并尝试将其设置为这样的主题

I am facing with problem. I am trying to make edit texts in my app look the same with the help of theme.
I have generated styles with the help of online tools (9-patch images) and tried to set it in my theme like this

   <!-- Base application theme. -->
    <style name="DefaultAppTheme" parent="Theme.AppCompat">
        <!-- Main theme colors -->
        <!--   your app branding color for the app bar -->
        <item name="colorPrimary">@color/blue</item>
        <!--   darker variant for the status bar and contextual app bars -->
        <item name="colorPrimaryDark">@color/darkblue</item>
        <!--   theme UI controls like checkboxes and text fields -->
        <item name="colorAccent">@color/cornflowerblue</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="android:editTextStyle">@style/EditTextDefault</item>
    </style>

我的编辑文本样式

<style name="EditTextDefault" parent="android:Widget.EditText">
        <item name="android:background">@drawable/edit_text_holo_light</item>
        <item name="android:textColor">@color/light_blue</item>
        <item name="android:layout_marginLeft">@dimen/margin_edit_text_default</item>
        <item name="android:layout_marginRight">@dimen/margin_edit_text_default</item>
        <item name="android:layout_marginTop">@dimen/margin_edit_text_default</item>
    </style>

但是,如果使用编辑文本而不为每个编辑文本手动指定样式,则此方法不起作用.

But this doesn't work if use edit text without specifying style manually for each edit text.

这不起作用

<EditText
    android:id="@+id/edit_text_login"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/edit_text_password"
    android:hint="@string/hint_enter_login"
    android:inputType="textEmailAddress" />

这有效

<EditText
    android:id="@+id/edit_text_login"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/edit_text_password"
    style="@style/EditTextDefault"
    android:hint="@string/hint_enter_login"
    android:inputType="textEmailAddress" />

我知道layout_ *参数不会在主题中使用,但是其他属性应该起作用.

I know that layout_* params will not affect if they are used in theme, but other attributes should work.

请帮助解决此问题.

推荐答案

代替此..

<item name="android:editTextStyle">@style/EditTextDefault</item>

使用此..

<item name="editTextStyle">@style/EditTextDefault</item>

这篇关于Android设置主题全局编辑文本样式不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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