I added Cyanea (a theme engine) into my app and the EditText style changed (see images, color doesn't matter. The first picture is how it looks now, and the second one is what I want the dialog to look like). How can I change old EditText style back?
My code:
dialog_input.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingBottom="4dp"
android:paddingTop="16dp">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/md_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/subj_name_input_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Hello, World!"
android:hint="#string/subject_name_dialog_hint"
android:inputType="text"
android:maxLines="1"
android:maxLength="32" />
</com.google.android.material.textfield.TextInputLayout>
</FrameLayout>
Use the Widget.Design.TextInputLayout style:
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.Design.TextInputLayout"
Related
I'd like to start using material components in my Android app, and I am having a bit of trouble with the MaterialAutoCompleteTextView. I want it to behave like a standard AutoCompleteTextView, and I prefer the OutlinedBox style. Furthermore, it should observe the completionThreshold property, expanding the dropdown only after three matching characters are entered.
There are four styles available for this component that are creating an outlined box:
Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu
Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu
Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense
Widget.MaterialComponents.TextInputLayout.OutlinedBox
However, the first two styles do not observe the completionThreshold and expand the dropdown immediately when they are in focus. The remaining ones seem broken and are probably not meant to be used with this component.
One option obviously is to use one of the latter styles and modify it. But this could end up a bit messy for this relatively complex component, and it seems a rather hacky way to make use of a built-in behavior.
What would be the right approach?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_margin="10dp">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:hint="Option 1"
app:helperText="OutlinedBox.Dense.ExposedDropdownMenu"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu">
<com.google.android.material.textfield.MaterialAutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionThreshold="3"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:hint="Option 2"
app:helperText="OutlinedBox.ExposedDropdownMenu"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu">
<com.google.android.material.textfield.MaterialAutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionThreshold="3"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:hint="Option 3"
app:helperText="OutlinedBox.Dense"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
<com.google.android.material.textfield.MaterialAutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionThreshold="3"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:hint="Option 4"
app:helperText="OutlinedBox"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionThreshold="3"
/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
Please try using setThreshold(3) on your AutoCompleteTextView in your java code, and also set app:endIconMode="none" in your xml, in the TextInputLayout that contains the AutoCompleteTextView.
I have a layout with two TextInputEditText and when I set a text on this (programmatically or with xml) and set focus on another TextInputEditText, the above label of TextInputEditText was hidden.
I want to show this label even a text was written in this.
My xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/whiteGray2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:orientation="horizontal"
android:weightSum="2"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp">
<com.google.android.material.textfield.TextInputLayout
style="#style/CustomBorderTextInputEditText"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:hint="#string/oldCount"
app:hintTextColor="#color/gray_text">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/input_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:inputType="none"
android:imeOptions="actionNext"
android:text="Hi How are you"
android:textColor="#color/gray_text"
android:textColorHint="#color/gray_text" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="#style/CustomBorderTextInputEditText"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:hint="#string/newCount">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/newCount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:textColorHint="#color/gray_text"
android:hint="#string/newCount"
android:textColor="#color/gray_text"
android:inputType="number"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
My style:
<style name="CustomBorderTextInputEditText" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="boxStrokeColor">#color/text_input_box_stroke</item>
<item name="hintTextColor">?attr/colorPrimary</item>
</style>
Your issue is here:
<com.google.android.material.textfield.TextInputEditText
android:textColorHint="#color/gray_text"
Remove android:textColorHint in the TextInputEditText and the use:
<com.google.android.material.textfield.TextInputLayout
app:hintTextColor="#color/colorSecondary"
android:textColorHint="#color/text_input_hint_selector"
The hintTextColor is the color of the label when it is collapsed and the text field is active.
The android:textColorHint is the color of the label in all other text field states (such as resting and disabled).
Just an example:
And this is the selector:
Here the TextInputLayout:
Without text:
Focused:
With text not focused:
Disabled:
Add it in your xml code :
android:focusableInTouchMode="true"
or
Add it in your java code :
EditText newCount = (EditText)findViewById(R.id.newCount);
newCount.setFocusable(true);
may be it usefull to you, just try it.
I found my answer. I should add textColorHint and set a color instead of add hintTextColor attribute. But now I am confused, What is the difference between both of them?
I am trying to create custom TextInputLayout. How can I create below custom TextInputLayout?
Any help or guidance will be well appreciated.
Just use the TextInputLayout provided by the Material Components Library.
Something like:
<com.google.android.material.textfield.TextInputLayout
app:boxBackgroundColor="#color/...."
app:boxStrokeColor="#color/..."
android:hint="..."
..>
<com.google.android.material.textfield.TextInputEditText
../>
</com.google.android.material.textfield.TextInputLayout>
About the rounded corners:
The default behaviour for the FilledBox (Widget.MaterialComponents.TextInputLayout.FilledBox) is a rounded box on the top corners (4dp) and a rectangular box on the bottom (0dp) as you can see in the image above.
If you would like a rounded box, I suggest you using the OutlinedBox style:
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
..>
The resul is:
Otherwise you can force a workaround like this (I don't like it since it breaks the material guideline):
<com.google.android.material.textfield.TextInputLayout
app:shapeAppearanceOverlay="#style/Rounded_ShapeAppearanceOverlay.MaterialComponents.TextInputLayout.FilledBox"
app:boxStrokeWidth="0dp"
app:boxStrokeColor="yourActivityBackgroundColor"
..>
where the app:shapeAppearanceOverlay attribute changes the shape of the bottom corners:
<style name="Rounded_ShapeAppearanceOverlay.MaterialComponents.TextInputLayout.FilledBox" parent="">
<item name="cornerSizeBottomLeft">#dimen/mtrl_shape_corner_size_small_component</item>
<item name="cornerSizeBottomRight">#dimen/mtrl_shape_corner_size_small_component</item>
</style>
where mtrl_shape_corner_size_small_component=4dp
try as below
<LinearLayout
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"
tools:context=".Main2Activity"
android:orientation="vertical"
android:background="#d4d4d4"
android:weightSum="1">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="fullname"
android:background="#FFFFFF"
android:layout_margin="10dp"
android:padding="10dp"
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Aalina Rodgers"
android:padding="10dp"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="fullname"
android:background="#FFFFFF"
android:layout_margin="10dp"
android:padding="10dp"
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Aalina Rodgers"
android:padding="10dp"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="fullname"
android:background="#FFFFFF"
android:layout_margin="10dp"
android:padding="10dp"
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Aalina Rodgers"
android:padding="10dp"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
I spent a lot of time in attempt to resolve this issue but without success for now...
when the application runs on android with RTL language. the label(hint) of the EditText is shown at the wrong position.
Desired result
ltr layout
RTL Layout
rtl layou
XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Login form container -->
<android.support.percent.PercentRelativeLayout
android:id="#+id/form_container"
android:layout_centerHorizontal="true"
app:layout_widthPercent="85%"
app:layout_heightPercent="30%"
app:layout_marginTopPercent="8%">
<!-- Username layout -->
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_username"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/input_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:inputType="textVisiblePassword|textNoSuggestions"
android:textDirection="ltr"
android:hint="#string/hint_username"/>
</android.support.design.widget.TextInputLayout>
<!-- Password layout -->
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_below="#+id/input_layout_username">
<EditText
android:id="#+id/input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:textDirection="anyRtl"
android:hint="#string/hint_password"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>
</android.support.percent.PercentRelativeLayout>
</android.support.percent.PercentRelativeLayout>
how can i fix the unnecessary margin in the RTL layout?
In addition, it would be great if it's possible to remove/hide the "visibility toggle"(eye icon) button!
Thank you!
to disable password toggle all you need is to add "passwordToggleEnabled" attribute to your TextInputLayout, for example:
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:passwordToggleEnabled="false">
<EditText
android:id="#+id/input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:textDirection="ltr"
android:hint="#string/hint_password"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>
How can I set the padding between the divider line and the error text (marked with the question mark in the image) in a TextInputLayout? I tried adding the padding in the style specified as errorTextAppearance but it had no effect.
EDIT: Here's the layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="test.textinputlayouttest.MainActivity">
<android.support.design.widget.TextInputLayout
android:id="#+id/address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="true"
app:errorTextAppearance="#style/Error">
<EditText
android:id="#+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter address"
android:inputType="textEmailAddress"
android:padding="26dp"/>
</android.support.design.widget.TextInputLayout>
</android.support.constraint.ConstraintLayout>
and the style:
<style name="Error" parent="TextAppearance.AppCompat">
<item name="android:textColor">#color/red</item>
<item name="android:paddingBottom">300dp</item>
</style>
if you need padding only between the divider line and the error text
use the previous example just change
android:padding="26dp" to - > android:layout_marginBottom="20dp"
<android.support.design.widget.TextInputLayout
android:id="#+id/usernameWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_marginBottom="20dp"
android:id="#+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="Username"/>
</android.support.design.widget.TextInputLayout>
You can get the error textview with
TextView textView = (TextView) inputLayout.findViewById(android.support.design.R.id.textinput_error);
And modify the layout params.
Just try this way.. I think this will work..
<android.support.design.widget.TextInputLayout
android:id="#+id/usernameWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:padding="26dp"
android:id="#+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="Username"/>
</android.support.design.widget.TextInputLayout>
Use android:layout_marginBottom="-10dp" in inner EditText
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.textfield.TextInputLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/textInputLayout"
style="#style/Widget.Design.TextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="-10dp"
tools:text="Text"
/>
</com.google.android.material.textfield.TextInputLayout>
works for version: com.google.android.material:material:1.5.0