Hey I am trying to create a dropdown box with the OutlinedBox theme but the theme is not working.
this is my xml code -
android:id="#+id/add_transaction_category_parent"
style="#style/Widget.Material3.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="300dp"
android:layout_height="80dp"
android:layout_marginTop="4dp"
android:theme="#style/TextInputLayoutStyle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/add_transaction_date_parent">
<AutoCompleteTextView
android:id="#+id/add_transaction_category"
android:layout_width="match_parent"
android:layout_height="60dp"
android:enabled="true"
android:hint="category"
android:inputType="none"
android:textColorHint="#color/white"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>
and this is the theme I have defined for the TextInputLayout
<style name="TextInputLayoutStyle" parent="Widget.Material3.TextInputLayout.OutlinedBox">
<item name="boxStrokeWidth">1dp</item>
</style>
this is the output UI
Output UI
thanks!
try this
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_marginTop="10dp"
android:ems="10"
app:hintTextColor="#color/white"
android:textColorHint="#color/white"
android:theme="#style/TextInputLayoutAppearance"
app:boxStrokeColor="#fff">
<EditText
android:id="#+id/textLogin_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:textColor="#color/white"
android:textColorHint="#color/white"
/>
</com.google.android.material.textfield.TextInputLayout>
create style.xml
<style name="TextInputLayoutAppearance" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="colorControlNormal">#color/white</item>
<item name="colorControlActivated">#color/white</item>
<item name="colorControlHighlight">#color/white</item>
</style>
</resources>
Related
I need the hint to have this form when the input is disabled:
That is what I have achieved so far:
I tried to add a background using HintTextAppearance in the style, but it was not applied.
<style name="HintAppearance" parent="TextAppearance.Design.Hint">
<item name="android:background">#drawable/bg_material_form</item>
<item name="android:padding">0dp</item>
</style>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:hintTextAppearance="#style/HintAppearance">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="value" />
</com.google.android.material.textfield.TextInputLayout>
I am working on login screen where I want to implememt material edit text with following view :
Following is my code :
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
style="#style/ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="This is Hint"/>
</com.google.android.material.textfield.TextInputLayout>
But OutlinedBox is not appearing. This is how it looks :
PLease help.
styles.xml theme as follows,
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
TextInputLayout sample:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="#string/user_name" />
</com.google.android.material.textfield.TextInputLayout>
Hope this will work for you!
Use this
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
Instead pf this
style="#style/ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox"
SAMPLE CODE
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="This is Hint"/>
</com.google.android.material.textfield.TextInputLayout>
OUTPUT
For Material 1.2.x library, please make sure your custom style should be the descendants of your app theme, otherwise will get error:
: IllegalArgumentException: The style on this component requires your app
theme to be Theme.MaterialComponents
This took me whole day to figure out:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.Bridge">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:statusBarColor" tools:targetApi="lollipop">#color/colorGreen</item>
<item name="bottomSheetDialogTheme">#style/AppBottomSheetDialogTheme</item>
<item name="textInputStyle">#style/TextInputLayoutStyle</item> // add it here
</style>
<style name="TextInputLayoutStyle"
parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="boxStrokeColor">#color/color_green</item>
<item name="boxStrokeWidth">1dp</item>
<item name="errorEnabled">true</item>
<item name="hintTextColor">#color/text_color</item>
</style>
Just changed the AppTheme to "Theme.MaterialComponents.Light.DarkActionBar" and it worked for me...
I had the same problem and I found out that my activity was declared like this:
public class MyActivity extends Activity {
}
And I had to change it to this:
public class MyActivity extends AppCompatActivity {
}
Also, as mentioned in other answers, check the AppTheme MaterialComponents
In my case it was difficult to move app from Theme.AppCompat.Light.NoActionBar to Theme.MaterialComponents.Light.NoActionBar.
But it is posible to set theme only to View (in my case TextInputLayout). At the end I have
<com.google.android.material.textfield.TextInputLayout
android:theme="#style/Theme.MaterialComponents.Light.NoActionBar"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:id="#+id/textField"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_marginStart="16dp"
android:layout_marginTop="23dp"
android:layout_marginEnd="16dp"
android:hint="Enter Pin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView24">
<com.google.android.material.textfield.TextInputEditText
style="#style/Widget.MaterialComponents.TextInputEditText.OutlinedBox"
android:id="#+id/secureEditTextAuthorizePin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberPassword" />
</com.google.android.material.textfield.TextInputLayout>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/default_text_input_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Default"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/default_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/filled_text_input_layout"
style="#style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="FilledBox"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/default_text_input_layout">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/filled_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/outlined_text_input_layout"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="OutlinedBox"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/filled_text_input_layout">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/outlined_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Check Once this Answer------------
Edit:
The bar I wanted to get rid of was the bar at the top which says testing. The text color I want to change is "testing#gmail.com" text which the user inputs:
Here is my XML for the login activity (I used the default login activity provided by android studio):
<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"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.uname.myapp.LoginActivity">
<!-- Login progress -->
<ProgressBar
android:id="#+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone" />
<ScrollView
android:id="#+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_password"
android:imeActionId="6"
android:imeActionLabel="#string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+id/email_sign_in_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="#string/action_sign_in"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
</LinearLayout>
I wanted to remove the bar at the top, so the solution shown online was to inherit from Theme.AppComtact.NoActionBar. Here is my style:
<style name="MyTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimary</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowBackground">#android:color/white</item>
<item name="android:textColorHint">#android:color/darker_gray</item>
<item name="android:textColor">#android:color/black</item>
</style>
Getting frustrated that I can't find documentation on the TextInputLayout and how to simply just change the font color when typing in the textfield. Tried searching on SO and other sites and couldn't find a solution.
I even tried <item name="android:colorControlNormal">#android:color/black</item> but it requires API level 21 and 15 is min right now.
Coming from a Python / Django background and first time trying to learn android development.
Can anyone point me in the right direction? Is there documentation that shows all the possible styling developers can apply on text?
My androidmanifest file has this in the application:
android:theme="#style/MyTheme"
if you want to remove action bar or titlebar use this style and make necessary true/false depending what you want and not.
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="#style/Theme.AppCompat.Light">
<item name="android:windowNoTitle">false</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
and in your manifest file
<activity
android:name=".activities.FullViewActivity"
android:theme="#style/Theme.AppCompat.Light.NoActionBar.FullScreen"
/>
and for changing font colour
<EditText
android:id="#+id/myEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Your Name"
android:textColor="#FF0000"
</EditText>
If you are looking for only setting TextInputLayout hint color then you should try this
app:hintTextAppearance="#style/text_appearance_color"
<android.support.design.widget.TextInputLayout
android:padding="8dp"
android:id="#+id/tilSample"
app:errorTextAppearance="#style/error_appearance"
app:hintTextAppearance="#style/text_appearance_color"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/etSample"
android:layout_margin="8dp"
android:padding="8dp"
android:hint="android"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
and for NoActionBar, your code seems to be fine just apply the theme in the manifest at the application level.
Edit:
style
<style name="editTextStyle" parent="#android:style/Widget.EditText">
<item name="android:background">#drawable/someBackground</item>
<item name="android:textColor">#808080</item>
<item name="android:layout_height">45dip</item>
<!--other attibutes goes here-->
</style>
It's very strange problem, this is my code:
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_pass"
android:layout_width="match_parent"
android:layout_height="37dp"
android:layout_marginTop="10dp"
android:layoutDirection="rtl"
android:src="#drawable/ic_https_grey600_18dp"
app:hintEnabled="false"
app:passwordToggleEnabled="true">
<EditText
android:id="#+id/password"
style="#style/edittexts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/ic_https_grey600_18dp"
android:drawableStart="#drawable/ic_https_grey600_18dp"
android:hint="رمز عبور"
android:gravity="right|center_vertical"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:transformPivotX="10dp"
app:passwordToggleEnabled="true" />
</android.support.design.widget.TextInputLayout>
I am using TextInputLayout for my login process, this is my java code :
pass_l.setErrorEnabled(true);
pass_l.setError(getString(R.string.wrong_pass));
When it show the error, the background of edit text gets red and it doesn't show the error below it , some thing like this :
how can I fix this problem? I don't want the edittext change the background color , just show the error below the editext as usual
Problem is with your style="#style/edittexts".Please shhare source code of it.It must be set Red in this style.
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_pass"
android:layout_width="match_parent"
android:layout_height="37dp"
android:layout_marginTop="10dp"
android:layoutDirection="rtl"
android:theme="#style/TextLabel"
android:src="#drawable/ic_https_grey600_18dp"
app:hintEnabled="false"
app:passwordToggleEnabled="true">
<EditText
android:id="#+id/password"
style="#style/edittexts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/ic_https_grey600_18dp"
android:drawableStart="#drawable/ic_https_grey600_18dp"
android:hint="رمز عبور"
android:gravity="right|center_vertical"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:transformPivotX="10dp"
app:passwordToggleEnabled="true" />
</android.support.design.widget.TextInputLayout>
<style name="TextLabel" parent="TextAppearance.AppCompat">
<!-- Hint color and label color in FALSE state -->
<item name="android:textColorHint">#color/Color Name</item>
<item name="android:textSize">20sp</item>
<!-- Label color in TRUE state and bar color FALSE and TRUE State -->
<item name="colorAccent">#color/Color Name</item>
<item name="colorControlNormal">#color/Color Name</item>
<item name="colorControlActivated">#color/Color Name</item>
</style>
You can try like this.
you can use this in your textInputLayoutTag :
app:errorEnabled="true"
app:errorTextAppearance="#style/ErrorAppearance"
example :
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_pass"
android:layout_width="match_parent"
android:layout_height="37dp"
android:layout_marginTop="10dp"
android:layoutDirection="rtl"
android:src="#drawable/ic_https_grey600_18dp"
app:hintEnabled="false"
app:passwordToggleEnabled="true"
app:errorEnabled="true"
app:errorTextAppearance="#style/ErrorAppearance">
<android.support.v7.widget.AppCompatEditText
android:id="#+id/password"
style="#style/FormStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/ic_https_grey600_18dp"
android:drawableStart="#drawable/ic_https_grey600_18dp"
android:hint="رمز عبور"
android:gravity="right|center_vertical"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:transformPivotX="10dp"
app:passwordToggleEnabled="true" />
</android.support.design.widget.TextInputLayout>
add ErrorAppearance and FormStyle in the styles.xml
<style name="ErrorAppearance" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/textError</item>
<item name="android:textSize">#dimen/font_small</item>
</style>
<style name="FormStyle">
<item name="android:maxLines">1</item>
<item name="android:drawablePadding">#dimen/spacing_small</item>
<item name="android:textColor">#color/textHint</item>
</style>
after the validation in the activity , you can :
pass_l.setError(getString(R.string.wrong_pass));
I created my own style for EditText, but it doesn't work
Style:
<style name="InputTextBox" parent="#android:style/Widget.EditText">
<item name="background">#drawable/text_area_box</item>
<item name="android:paddingLeft">16dp</item>
<item name="android:paddingRight">16dp</item>
<item name="android:paddingTop">8dp</item>
<item name="android:paddingBottom">8dp</item>
<item name="android:gravity">top</item>
</style>
EditText in XML:
<EditText
app:theme="#style/InputTextBox"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="#+id/spinner_to"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="#+id/spinner_from"
android:layout_marginRight="0dp"
app:layout_constraintRight_toRightOf="#+id/spinner_to"
app:layout_constraintHorizontal_bias="0.0"
android:hint="#string/translate_text_input_hint"
android:layout_marginBottom="0dp"
app:layout_constraintBottom_toTopOf="#+id/guideline"
app:layout_constraintVertical_bias="0.0"
android:id="#+id/et_input_text" />
I tried to change parent in styles to Widget.AppCompat.EditText, Base.Widget.AppCompat.EditText and others but still have no result
For setting style on EditText you need to set android:theme.
<EditText
android:theme="#style/InputTextBox"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="#+id/spinner_to"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="#+id/spinner_from"
android:layout_marginRight="0dp"
app:layout_constraintRight_toRightOf="#+id/spinner_to"
app:layout_constraintHorizontal_bias="0.0"
android:hint="#string/translate_text_input_hint"
android:layout_marginBottom="0dp"
app:layout_constraintBottom_toTopOf="#+id/guideline"
app:layout_constraintVertical_bias="0.0"
android:id="#+id/et_input_text" />