小编exl*_*icx的帖子

Android在主题中全局设置编辑文本样式不起作用

我面临着问题.我试图让我的应用程序中的编辑文本在主题的帮助下看起来一样.
我已经在在线工具(9-patch图像)的帮助下生成了样式,并尝试在我的主题中设置它

   <!-- 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>
Run Code Online (Sandbox Code Playgroud)

我的编辑文本样式

<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>
Run Code Online (Sandbox Code Playgroud)

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

这不起作用

<EditText
    android:id="@+id/edit_text_login"
    android:layout_width="match_parent" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-theme android-fragments

18
推荐指数
2
解决办法
2万
查看次数