exl*_*icx 18 android android-layout android-theme android-fragments
我面临着问题.我试图让我的应用程序中的编辑文本在主题的帮助下看起来一样.
我已经在在线工具(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"
android:layout_height="wrap_content"
android:layout_above="@+id/edit_text_password"
android:hint="@string/hint_enter_login"
android:inputType="textEmailAddress" />
Run Code Online (Sandbox Code Playgroud)
这有效
<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" />
Run Code Online (Sandbox Code Playgroud)
我知道layout_*params不会影响它们是否在主题中使用,但其他属性应该有效.
请帮助解决这个问题.
Jon*_*put 53
而不是这个..
<item name="android:editTextStyle">@style/EditTextDefault</item>
Run Code Online (Sandbox Code Playgroud)
用这个..
<item name="editTextStyle">@style/EditTextDefault</item>
Run Code Online (Sandbox Code Playgroud)
使用此@android:style/Widget.EditText
替代parent="android:Widget.EditText"
。我希望它会帮助你。
请阅读此 SO 答案 为所有 EditText 设置一致的样式
<style name="EditTextDefault" parent="@android:style/Widget.EditText">
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
16599 次 |
最近记录: |