Android的 - 设置默认样式的EditText视图不工作 [英] Android - Setting default style for EditText view is not working
问题描述
我试图设置编辑文本视图默认样式。在这个例子中,我设置默认样式EDITTEXT以及为TextView的。
I am trying to set default style for edit text view. In this example, I have set default style for editText as well as for textView.
下面是我从styles.xml值文件夹:
Here is my styles.xml from values folder:
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:editTextStyle">@style/AppTheme.EditText</item>
<item name="android:textViewStyle">@style/AppTheme.TextView</item>
</style>
<style name="AppTheme.EditText" parent="android:Widget.EditText">
<item name="android:textColor">@color/red</item>
<item name="android:padding">10dp</item>
</style>
<style name="AppTheme.TextView" parent="android:Widget.TextView">
<item name="android:textColor">@color/red</item>
<item name="android:padding">10dp</item>
</style>
</resources>
如下面的快照所示,我已经添加了两个EDITTEXT和两个TextView的布局
As shown in the snapshots below, I have added two editText and two textView in layout.
下面是我的布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="TextView1" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_marginTop="20dp"
android:text="TextView2" />
<EditText
android:id="@+id/editText1"
style="@style/AppTheme.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView2"
android:layout_marginTop="20dp"
android:ems="10"
android:text="EditText1" >
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_marginTop="20dp"
android:ems="10"
android:text="EditText2" >
</EditText>
</RelativeLayout>
现在的问题是,对于TextView的默认样式工作正常,但对于EDITTEXT查看它并不反映作风。如果我明确设置样式EDITTEXT然后它反映如预期(作为editText1完成),而不是默认。对于editText2文本颜色应该是红色的,但事实并非如此。我缺少的东西吗?
Now the issue is, default style for textView works fine but for editText view it does not reflect the style. If I explicitly set style for editText then it reflects as expected (as done for editText1), but not by default. Text color for editText2 should be red but it's not. Am I missing something?
推荐答案
Hi prashant..just i copied your code in my project. for me its working
do you want like this? or anything else?
这篇关于Android的 - 设置默认样式的EditText视图不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!