2017-03-09 26 views
2

Edittext setError方法在android 6.0中不显示文本,但在android 5.0中完美工作。我已经尝试了很多解决方案,但没有得到解决方案,我尝试了所有的解决方案,所以如何解决这个问题? enter image description hereEdittext setError在android 6.0中不显示消息

这是我的xml:

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/toolbar_create_page" 
    android:fillViewport="false"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="180dp" 
      android:id="@+id/ivPageBanner" 
      android:src="@drawable/bg_timeline" 
      android:scaleType="fitXY" /> 

     <ImageView 
      android:layout_width="80dp" 
      android:layout_height="80dp" 
      android:id="@+id/ivPageDp" 
      android:layout_alignParentBottom="false" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_marginTop="140dp" 
      android:layout_marginLeft="15dp" 
      android:src="@drawable/flagwithcamera" /> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/etPageName" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_below="@+id/ivPageDp" 
      android:layout_marginTop="20dp" 
      android:hint="Page name" 
      style="@style/EditTextTheme" 
      android:theme="@style/EditTextTheme" 
      android:textCursorDrawable="@drawable/black_cursor" 
      android:layout_marginLeft="15dp" 
      android:layout_marginRight="15dp" 
      android:textColorHint="@color/hint_foreground_material_light" /> 
    </RelativeLayout> 
</ScrollView> 

这里是我的风格的EditText:

<style name="EditTextTheme" parent="Widget.AppCompat.EditText"> 
    <item name="android:textColor">@color/transparent</item> 
    <item name="android:textColorHint">@color/transparent</item> 
    <item name="colorAccent">@color/colorPrimary</item> 
    <item name="colorControlNormal">@color/colorPrimary</item> 
    <item name="colorControlActivated">@color/colorPrimary</item> 
</style> 

这里是我Colors.xml:

<color name="colorPrimary">#64100b</color> 
<color name="transparent">#fc000000</color> 
+0

发表您的XML代码 – Akshay

+0

发表您的EditTextTheme风格的代码也 –

回答

4

我得到了我的解决方案。刚从我的Edittext中删除:

android:theme="@style/EditTextTheme" 

原因在setError的文本下面划线。

好吧,但这些强调来自哪里呢?

android:theme是查看的属性,当你设置样式为android:theme,这种风格将被ContextThemeWrapper与上下文主题包,而在视通货膨胀。

因此,这意味着,如果你设置android:theme属性与风格,包含android:background项目像

<item name="android:background">@color/red</item> 

这个主题所有者的每个孩子视图将有一个绿色的背景。

"Widget.AppCompat.EditText"是一种风格和参考?attr/editTextBackground作为"android:background"。并在v21/values-21.xml文件@drawable/abc_edit_text_material中定义为editTextBackground

由于https://stackoverflow.com/a/42355788/5909385

1

我认为,这确实显示,但它被切断了。尝试使用浮动标签&将错误设置为TextInputLayout引用。请让我知道,如果你仍然面临问题

+0

TextInputLayout SETERROR工作完美,但我想要的EditText SETERROR –

+0

可能是你的微调部件重叠的错误信息出现。尝试暂时删除微调器布局,然后重试。 –

+0

尝试过您的解决方案,但没有获得完美的输出结果。 –