Edittext setError method is not showing text in android 6.0 but working perfectly in android 5.0. I have tried many solutions but don't get solution and i tried all solution of Android 6 EditText.setError not working correctly, So how to fix this issue?
This is my 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>
Here is my style for 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>
and here is my Colors.xml:
<color name="colorPrimary">#64100b</color>
<color name="transparent">#fc000000</color>
I got my solution. Just removed this from my Edittext:
android:theme="#style/EditTextTheme"
Reason is underline below text of setError.
Alright, but where are these underlines come from?
android:theme is an attribute of View and when you set a style as android:theme, that style will be wrapped by ContextThemeWrapper with context theme while in inflation of view.
So that means, if you set android:theme property with style that contains android:background item like
<item name="android:background">#color/red</item>
every child view of this theme owner will be have a green background.
"Widget.AppCompat.EditText" is a style and references ?attr/editTextBackground as a "android:background". And in v21/values-21.xml file #drawable/abc_edit_text_material is defined as editTextBackground.
Thanks to https://stackoverflow.com/a/42355788/5909385
I think, It does showing but it is bit chopped off. Try using Floating Labels & Set Error to TextInputLayout reference. Please let me know if you still facing issue
Related
When I use style="#style/Widget.Design.TextInputLayout" for TextInputLayout, setting app:errorIconDrawable does nothing. It only works when I don't set the style and let it inherit the application theme (Theme.MaterialComponents.Light.NoActionBar). app:endIconDrawable also doesn't work and I cannot find an alternative/solution to this problem. Please help!
The following works while inheriting the application theme:Theme.MaterialComponents.Light.NoActionBar but I don't want this style, particularly the underline doesn't align with the texts:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/login_password_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="username"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/login_password_input_text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
This uses the style that I need but will not show the error icon:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/login_password_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="username"
style="#style/Widget.Design.TextInputLayout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/login_password_input_text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
Since you are using the legacy style Widget.Design.TextInputLayout it doesn't have support for all text field features that the *.OutlinedBox and *.FilledBox styles have.
You can't set the errorIconDrawable in the xml and you have to call TextInputLayout.setErrorIconDrawable after TextInputLayout.setError.
login_password_input_layout.setError("Error text!!");
login_password_input_layout.setErrorIconDrawable(R.drawable....);
hmm, see if you use directly below
style="#style/Widget.Design.TextInputLayout"
then your error drawable becomes null.
What I would suggest you is, create a style, modify the values as you like
<style name="TextLabel" parent="Widget.Design.TextInputLayout">
<item name="android:textColorHint">#f32</item>
<item name="android:textSize">20sp</item>
<item name="colorAccent">#4CAF50</item>
<item name="errorIconDrawable">#drawable/ic_baseline_error_24</item>
<item name="colorControlNormal">#673AB7</item>
<item name="colorControlActivated">#E91E63</item>
<item name="errorEnabled">true</item>
</style>
and then apply it to via
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/login_password_input_layout"
android:theme="#style/TextLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:hint="username"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/login_password_input_text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
This should solve.
I am setting style,color and size to textview , that is working
this is my code `
<android.support.v7.widget.AppCompatTextView
android:id="#+id/txt_agent_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:gravity="center"
android:textColor="#000"
android:textSize="14sp"
android:textStyle="italic"/>
Please check your parent layout is correct some times transparent layer or such things create visualise problem with colour
<android.support.v7.widget.AppCompatTextView
android:id="#+id/txt_agent_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="10dp"
android:gravity="center"
android:text="AppCompatTextView"
android:textColor="#FFFFFF"
android:textSize="114dp"
android:textStyle="italic" />
Use Dimension for setting up a text size ,always avoid hard coding
If you want to set same style for text-color,text-size and text-style than you can create something like
<style name="MyTextAppearance" parent="TextAppearance.AppCompat">
<item name="android:textColor">?android:textColorPrimary</item>
<item name="android:textSize">#dimen/abc_text_size_body_1_material</item>
<item name="textColor">?textColorPrimary</item>
<item name="textStyle">italic</item>
</style>
All of my searches has led me to guides on how to change the text color of the spinner choices, but how do I change the color of the text and arrow on the spinner itself?
Here's a snip of my spinner. It's supposed to say "Mercury".
Here's my attempt at the style. It did change the arrow to white, but not the text. I only applied it to the spinner since it will mess up the rest of the activity.
<style name="Theme.LightText2" parent="AppTheme">
<item name="android:editTextColor">#ffffff</item>
<item name="android:textColorPrimary">#ffffff</item>
<item name="android:textColorSecondary">#ffffff</item>
<item name="android:textColorTertiary">#ffffff</item>
<item name="android:textColorPrimaryInverse">#ffffff</item>
<item name="android:textColorSecondaryInverse">#ffffff</item>
<item name="android:textColorTertiaryInverse">#ffffff</item>
</style>
UPDATE: I tried to apply it to the activity itself via the manifest and it worked, but it's messed up the rest of my activity.
If you want to achieve this do one thing , Take one textview and set arrow icon on right(Drawableright) customize your text text view as you wont and on click open dialog with single selection and on item selected set text to textview
Try like this and use spnrSelect.performClick(); on click of rlSpinner to open spinner
<RelativeLayout
android:id="#+id/rlSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/scale_20dp"
android:layout_marginRight="#dimen/scale_20dp"
android:layout_marginTop="#dimen/scale_1dp"
android:background="#null"
android:clickable="true">
<Spinner
android:id="#+id/spnrSelect"
android:layout_width="match_parent"
android:layout_height="0dp"
android:clickable="true"
android:dropDownWidth="#dimen/scale_300dp"
android:scrollbars="none"
android:spinnerMode="dropdown" />
<TextView
android:id="#+id/txtSelect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingBottom="#dimen/scale_1dp"
android:paddingRight="#dimen/scale_1dp"
android:paddingTop="#dimen/scale_1dp"
android:text="#string/txtSelect"
android:textColor="#color/edt_hint"
android:textColorHint="#color/edt_hint"
android:textSize="#dimen/txt_12" />
<ImageView
android:id="#+id/spnrDownArrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="#dimen/scale_10dp"
android:background="#drawable/arrow_icon"
android:rotation="90" />
</RelativeLayout>
Create array adapter which will inflate TextView from Layout_resource
then set your color to inflated TextView
your_spinnersp.setAdapter(new ArrayAdapter<>(context,R.layout.txt_spinner,lst_data));
in layout add TextView
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="8dp" android:textSize="16sp"
android:background="#ff0000"
android :textColor="#ffff00"
android:layout_width="match_parent" android:layout_height="wrap_content"/>
I have a spinner after i loaded data into it. the style is not as my expected.
Spinner code
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinnerGender"
android:spinnerMode="dropdown"
android:layout_marginLeft="-5dp"
android:layout_marginTop="5dp"/>
Current style.
My expected
How can i change theme/style the spinner
try this,
<Spinner
android:id="#+id/spinnerGender"
style="#android:style/Widget.Holo.Light.Spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="-5dp"
android:layout_marginTop="5dp"
android:spinnerMode="dropdown" />
otherwise you can create custome style and use
Example at following link:
http://androidopentutorials.com/android-how-to-get-holo-spinner-theme-in-android-2-x/
Another approach is using the styles.xml file
<!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:spinnerStyle">#android:style/Widget.Holo.Light.Spinner</item>
</style>
I have a strange issue regarding showing text selected from spinner in my motorola Defy 2.2 .I have created a layout which has a spinner from which user can select one option, but the problem is even though I select an item from spinner list it never display that item in box.I know the text-color in defy by default is white and my layout background is also white which would hide the text, but I have also specified the text-color property in layout for spinner as black color and it still not displaying the text.My layout looks like the following:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20.0dip"
android:layout_marginRight="20.0dip"
android:layout_marginTop="7.0dip"
android:background="#drawable/rectangle_shape" >
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="right|center"
android:gravity="right|center"
android:paddingBottom="7.0dip"
android:paddingLeft="10.0dip"
android:paddingRight="8.0dip"
android:paddingTop="7.0dip"
android:text="Concession"
android:textColor="#color/white"
android:textSize="16.0sp" />
<Spinner
android:id="#+id/CSpinner"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:background="#drawable/rectangle_shape_middle"
android:entries="#array/C_arrays"
android:paddingLeft="6.0dip"
android:prompt="#string/C_prompt"
android:textColor="#color/black"
android:textSize="16.0sp" />
<ImageView
android:id="#+id/SpinnerSelector"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="right"
android:background="#drawable/rectangle_shape_end"
android:paddingLeft="3.0dip"
android:paddingRight="3.0dip"
android:src="#drawable/ic_navigation_expand" />
</LinearLayout>
</LinearLayout>
The code is working fine on other phones like samsung galaxy s2,s3 and Note as well.Please help me out.
Thanks in Advance
I am answering my own question as it might help others.The problem with Motorola defy is that it has a default text color set to white and for spinner we can't use android:textColor="#color/white" as they won't work.To change text color of spinner we need use following code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MooTheme" parent="android:Theme">
<item name="android:spinnerItemStyle">#style/MooSpinnerItem</item>
</style>
<style name="MooSpinnerItem" parent="android:Widget.TextView.SpinnerItem">
<item name="android:textAppearance">#style/MooTextAppearanceSpinnerItem</item>
</style>
<style name="MooTextAppearanceSpinnerItem" parent="android:TextAppearance.Widget.TextView.SpinnerItem">
<item name="android:textColor">#F00</item>
</style>
</resources>
Now we just need to apply MooTheme to our application and you will start seeing the text in spinner.