TextInputLayout Hint gravity bottom - android

The Hint is always vertically centred and I want it to be aligned to the bottom of the view close to the border with a bit padding. I managed to do it for the text of the TextInputEditText but I cannot do it for the hint.
Here's how it looks
And here is my layout XML:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/first_name_layout"
style="#style/My.TextInputLayout.FilledBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/first_name"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/first_name_edit_text"
style="#style/TextInputEditTextForm"
android:inputType="textPersonName" />
</com.google.android.material.textfield.TextInputLayout>
And my styles.xml
<style name="My.TextInputLayout.FilledBox" parent="Widget.MaterialComponents.TextInputLayout.FilledBox">
<item name="materialThemeOverlay">#style/MyThemeOverlayFilledPadding</item>
<item name="android:gravity">bottom</item>
<item name="android:textColorHint">#color/gray</item>
<item name="boxBackgroundColor">#android:color/transparent</item>
<item name="boxStrokeColor">#color/grey_little</item>
<item name="boxStrokeWidth">0.5dp</item>
<item name="hintTextAppearance">#style/FormInputLabel</item>
<item name="hintTextColor">#color/gray</item>
</style>
<style name="MyThemeOverlayFilledPadding">
<item name="colorControlActivated">#color/gray_light</item>
<item name="editTextStyle">#style/MyTextInputEditText_filledBox_padding</item>
</style>
<style name="MyTextInputEditText_filledBox_padding" parent="#style/Widget.MaterialComponents.TextInputEditText.FilledBox">
<item name="android:paddingBottom">5dp</item>
</style>
<style name="TextInputEditTextForm" >
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:gravity">bottom</item>
<item name="android:lines">1</item>
<item name="android:textColor">#color/gray_x_dark</item>
<item name="android:textSize">#dimen/text_xx_small</item>
</style>
<style name="MyThemeOverlayFilledPaddingHint">
<item name="android:paddingBottom">5dp</item>
<item name="android:gravity">bottom</item>
</style>
<style name="FormInputLabel" parent="TextAppearance.Design.Hint">
<item name="android:textSize">#dimen/text_xxxx_small</item>
<item name="materialThemeOverlay">#style/MyThemeOverlayFilledPaddingHint</item>
<item name="android:gravity">bottom</item>
</style>

The hint is drawn by helper class CollapsingTextHelper which is available in private-package scope.
You can access the field via reflection but accessing private field is only available on pre Orea devices

Related

Why is my EditText style not being applied?

I try like this:
styles.xml:
<style name="EditTextStyle" parent="Widget.AppCompat.EditText">
<item name="android:layout_marginBottom">12dp</item>
<item name="android:backgroundTint">#color/editTextUnderline</item>
<item name="android:drawableLeft">#drawable/ic_sample_action</item>
<item name="android:drawablePadding">8dp</item>
<item name="android:paddingTop">15dp</item>
<item name="android:paddingBottom">25dp</item>
<item name="android:textColor">#color/colorTextPrimary</item>
<item name="android:textColorHint">#color/editTextHintColor</item>
<item name="android:textSize">16sp</item>
<item name="android:fontFamily">#font/viga</item>
<item name="android:inputType">text</item>
</style>
And then I use it in layout file:
<EditText
style="#style/EditTextStyle"
android:id="#+id/input_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Title"
android:text="#={viewModel.title}" />
However I do not see any changes. Why could that be?
I chanded style parent to #style/Widget.AppCompat.EditText and it worked.

In Android, AutoCompleteTextView is not centered while using Exposed Dropdown Menus in Material Design Component

In newly published Material Design Component, there is no Spinner component. That's why I want to use Exposed Dropdown Menus to implement something similar like Spinner. The Problem I am facing is AutoCompleteTextView is not aligned in center compare to the endIconDrawable. My Code is given bellow
activity.main.xml
<com.google.android.material.textfield.TextInputLayout
style="#style/OutLinedEditTextStyle.Spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Select Country"
android:layout_margin="#dimen/_10sdp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.578"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/materialToolbar"
app:layout_constraintVertical_bias="0.0">
<AutoCompleteTextView
android:id="#+id/filled_exposed_dropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionThreshold="1"
android:dropDownVerticalOffset="#dimen/_5sdp"/>
</com.google.android.material.textfield.TextInputLayout>
style.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="OutLinedEditTextStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="boxBackgroundMode">outline</item>
<item name="boxBackgroundColor">#color/colorWindowBackground</item>
<item name="boxStrokeColor">#color/colorTextPrimary</item>
<item name="boxStrokeErrorColor">#color/red</item>
<item name="boxStrokeWidth">#dimen/_2sdp</item>
<item name="boxStrokeWidthFocused">#dimen/_2sdp</item>
<item name="errorTextColor">#color/red</item>
<item name="errorEnabled">true</item>
<item name="hintEnabled">true</item>
<item name="hintTextColor">#color/colorTextPrimary</item>
<item name="android:textColorHint">#color/colorTextSecondary</item>
</style>
<style name="OutLinedEditTextStyle.Spinner">
<item name="materialThemeOverlay">#style/ThemeOverlay.MaterialComponents.AutoCompleteTextView.FilledBox</item>
<item name="endIconMode">custom</item>
<item name="endIconDrawable">#drawable/ic_download</item>
<item name="endIconContentDescription">Drop down</item>
</style>
</resources>
Finally I can solve the problem. The fault was, I inherit the wrong Parent class of Dropdown menu.
<style name="SpinnerStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="boxBackgroundMode">outline</item>
<item name="boxBackgroundColor">#color/colorWindowBackground</item>
<item name="boxStrokeColor">#color/colorTextPrimary</item>
<item name="boxStrokeErrorColor">#color/red</item>
<item name="boxStrokeWidth">#dimen/_2sdp</item>
<item name="boxStrokeWidthFocused">#dimen/_2sdp</item>
<item name="errorTextColor">#color/red</item>
<item name="errorEnabled">true</item>
<item name="hintEnabled">true</item>
<item name="hintTextColor">#color/colorTextPrimary</item>
<item name="android:textColorHint">#color/colorTextSecondary</item>
<item name="endIconMode">clear_text</item>
</style>

TextInputLayout outline hint color

I have a strange bug on a TextInputLayout. The color of the hint of the com.google.android.material.textfield.TextInputEditText goes white on focus.
this is how I am setting it:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/inputEmail"
style="#style/EditText.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="16dp"
app:boxStrokeColor="#color/colorBrand">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/editTextEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:hint="#string/edt_hint_email"
android:inputType="textEmailAddress"
android:textAlignment="viewStart" />
</com.google.android.material.textfield.TextInputLayout>
..and this is the style:
<style name="EditText.OutlinedBox" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="android:minHeight">56dp</item>
<item name="android:textSize">18sp</item>
<item name="android:fontFamily">#font/dubai_regular</item>
<item name="hintEnabled">true</item>
</style>
edit: add style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TextAppearance.AppCompat.Title" parent="TextAppearance.AppCompat.Large">
<item name="android:textColor">#color/colorTextPrimary</item>
<item name="android:layout_gravity">center_vertical</item>
</style>
<style name="EditText.OutlinedBox" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="android:minHeight">56dp</item>
<item name="android:textSize">18sp</item>
<item name="android:fontFamily">#font/dubai_regular</item>
<item name="hintEnabled">true</item>
</style>
<style name="Button" parent="Widget.MaterialComponents.Button">
<item name="cornerRadius">10dp</item>
<item name="backgroundTint">#color/colorAccent</item>
<item name="android:minHeight">56dp</item>
<item name="android:textAllCaps">false</item>
<item name="android:fontFamily">#font/dubai_bold</item>
<item name="android:elevation">0dp</item>
<item name="android:stateListAnimator">#null</item>
</style>
<style name="Button.Primary">
<item name="backgroundTint">#color/colorAccent</item>
</style>
<style name="DialogAnimation">
<item name="android:windowEnterAnimation">#anim/slide_up_dialog</item>
<item name="android:windowExitAnimation">#anim/slide_out_down</item>
</style>
<style name="Tag" parent="TextAppearance.AppCompat">
<item name="android:background">#drawable/tag_navy</item>
<item name="android:fontFamily">#font/dubai_bold</item>
<item name="android:textSize">12sp</item>
<item name="android:paddingStart">16dp</item>
<item name="android:paddingEnd">16dp</item>
<item name="android:paddingTop">6dp</item>
<item name="android:paddingBottom">6dp</item>
<item name="android:gravity">center</item>
<item name="android:textColor">#color/colorWhite</item>
</style>
<style name="Tag.Closed">
<item name="android:background">#drawable/ic_tag_closed</item>
<item name="android:textAllCaps">true</item>
</style>
<style name="Tab.TextAppearance" parent="TextAppearance.AppCompat">
<item name="android:textSize">14sp</item>
<item name="android:fontFamily">#font/dubai_bold</item>
</style>
</resources>
Just Add Hint text color inside your EditText.OutlinedBox style.
TextInputLayout have specified the property for changing the color of hint and error.
<item name="android:textColorHint"> #Your Color </item>
<item name="hintTextColor"> #Your Color </item>
Here I have two different Hint Text color specified
1) android:textColorHint and 2) hintTextColor
Because this both works differently.
android:textColorHint property will handle the text color of hint of the EditText.
hintTextColor property will handle the text color of hint on the outline box.
Try app:hintTextAppearance="#style/hintText" for TextInputLayout
<style name="hintText" parent="android:TextAppearance">
<item name="android:textColor">your color</item>
</style>

How to change the color of the text or the divider color of the date picker in a DialogFragment?

I have been trying to update the textcolor and the divider color of the DatePicker but in vain.
My Datepicker inside the Fragment -
<DatePicker xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/datePickerContainer"
style="#style/wertyui"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:calendarViewShown="false"
android:spinnersShown="true" />
The style of datepicker-
<style name="wertyui" parent="#android:style/Widget.Holo.Light">
<item name="android:datePickerMode">spinner</item>
<item name="android:calendarViewShown">false</item>
<item name="android:spinnersShown">true</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:colorAccent">#color/colorAccent</item>
<item name="android:colorControlNormal">#color/colorAccent</item>
<item name="android:colorControlActivated">#color/colorAccent</item>
<item name="android:textColorPrimary">#color/colorAccent</item>
<item name="android:textColorPrimaryInverse">#color/colorAccent</item>
</style>
The Style of the Activity -
<style name="themex" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">#cccccc</item>
<item name="android:colorPrimary">#color/white</item>
<item name="android:listDivider">#color/white_pressed</item>
<item name="colorPrimary">#color/colorAccent</item>
<item name="android:textColor">#212121</item>
<item name="android:colorAccent">#color/colorAccent</item>
<item name="colorControlActivated">#color/colorAccent</item>
<item name="android:windowDisablePreview">true</item>
<item name="android:windowAnimationStyle">#null</item>
<item name="android:itemBackground">#ffffff</item>
<item name="actionMenuTextColor">#212121</item>
<item name="android:letterSpacing">0.03</item>
<item name="android:colorPrimaryDark">#CCCCCC</item>
</style>
I have tried every way but the colors are not changing.
As you can see, i am using #android:style/Widget.Holo.Light theme.
On Lollipop, the divide color is default blue but on Android pie or oreo it is BLack. How to change the Color.
I don't want to use any library. Is there any direct way to do this using XML or programmatically?

Styled EditText inside a compound view doesn't gain focus

I have made a very simple compound view:
<LinearLayout>
<ImageView />
<EditText />
</LinearLayout>
Everything worked fine until I have decided to style the Edit text throught my project:theme:
<style name="Theme.MyProject" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">#style/Widget.Theme.MyProject.ActionBar</item>
<item name="android:actionBarStyle" tools:ignore="NewApi">#style/Widget.Playout.ActionBar</item>
<item name="android:buttonStyle">#style/Theme.Theme.MyProject.Button</item>
<item name="android:editTextStyle">#style/Theme.Theme.MyProject.EditText</item>
</style>
and
<style name="Theme.Playout.EditText">
<item name="android:textSize">15sp</item>
<item name="android:textColor">#color/field_text</item>
<item name="android:background">#color/field</item>
<item name="android:minHeight">50dp</item>
<item name="android:padding">5dp</item>
<item name="android:gravity">center</item>
<item name="android:fontFamily">sans-serif-light</item>
</style>
Now my EditText is beautiful but is not gaining focus so text cannot being entered (so useful). It works fine adding values directly to the Compound view from layout but I whould like to do it from a confortable theme.
Thanks in advance!
Try this:
<style name="Theme.Playout.EditText">
<item name="android:textSize">15sp</item>
<item name="android:textColor">#color/field_text</item>
<item name="android:background">#color/field</item>
<item name="android:minHeight">50dp</item>
<item name="android:padding">5dp</item>
<item name="android:gravity">center</item>
<item name="android:fontFamily">sans-serif-light</item>
<!-- I added these attributes: -->
<item name="android:focusable">true</item>
<item name="android:focusableInTouchMode">true</item>
<item name="android:clickable">true</item>
</style>

Categories

Resources