I have Text Field with some styles applyed to change the background aspect.
For some reason the input text when writing is cut off.
One solution i found was to increase the overall height, but i would like to keep the 50dp height
The Text Field:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/add_description_layout"
style="#style/OutlinedRoundedBox"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:hint="#string/add_trans_description_title"
android:layout_marginTop="18dp">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/add_description_input"
android:layout_width="match_parent"
android:layout_height="50dp"
android:inputType="textAutoComplete"
android:textCursorDrawable="#null" />
</com.google.android.material.textfield.TextInputLayout>
The styles i am using on the text field:
<style name="OutlinedRoundedBox" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="shapeAppearanceOverlay">
#style/ShapeAppearanceOverlay.MyApp.TextInputLayout.Rounded
</item>
<item name="boxBackgroundColor">#color/secondaryColor</item>
<item name="boxStrokeWidth">0dp</item>
<item name="boxStrokeColor">#color/secondaryDarkColor</item>
<item name="android:textColorHint">#color/backgroundText</item>
<item name="android:textColor">#color/backgroundText</item>
<item name="hintTextColor">#color/backgroundText</item>
<item name="hintTextAppearance">#style/TextInputLayoutHintText</item>
<item name="helperTextTextAppearance">#style/TextInputLayoutHelperText</item>
<item name="android:theme">#style/ThemeOverlay.TextInputEditText.OutlinedBox.CustomFont</item>
</style>
<style name="ThemeOverlay.TextInputEditText.OutlinedBox.CustomFont" parent="ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox">
<item name="editTextStyle">#style/TextInputEditText.OutlinedBox.CustomFont</item>
</style>
<style name="TextInputEditText.OutlinedBox.CustomFont" parent="Widget.MaterialComponents.TextInputEditText.OutlinedBox">
<item name="android:fontFamily">#font/fira_sans</item>
</style>
<style name="TextInputLayoutHintText" parent="TextAppearance.Design.Hint">
<item name="android:fontFamily">#font/fira_sans</item>
</style>
<style name="TextInputLayoutHelperText" parent="TextAppearance.Design.HelperText">
<item name="android:fontFamily">#font/fira_sans</item>
</style>
<style name="ShapeAppearanceOverlay.MyApp.TextInputLayout.Rounded" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">32dp</item>
</style>
Current aspect:
Is there a way around this?
Thanks in advance
I think this is to be expected. By default android uses 14sp text size and the height you specified might not be enough for the text size. You can try using small text size with attribute android:textSize for TextInputEditText
Related
I have one button and letterspacing is not working with it. Please check my following snippet code
<style name="ButtonText_v2" parent="TextAppearance.AppCompat">
<item name="fontFamily">#font/silka_regular</item>
<item name="android:letterSpacing">0.1</item>
<item name="android:textSize">#dimen/dimen_14dp</item>
</style>
<style name="PrimaryButton_v2" parent="Widget.AppCompat.Button">
<item name="android:background">#drawable/button_selector_primary</item>
<item name="android:textColor">#color/white</item>
<item name="textAllCaps">true</item>
<item name="textAppearance">#style/ButtonText_v2</item>
</style>
layout.xml File
<Button
android:text="Button"
android:layout_height="56dp"
android:layout_width="200dp"
style="#style/PrimaryButton_v2"
android:layout_margin="15dp"
/>
You can't apply letter spacing in button/custom button because their is some limitation in button component in which you can't make text appearance and background customization and more limitation
the solution for this is instead of button you can use text view and make custom text view it will also work similar to button and customize it according to requirement.
for example :-
https://stackoverflow.com/questions/9477336/how-to-make-a-custom-textview#:~:text=Create%20a%20Custom%20View%20for%20Textview.%20Make%20the,values%20Make%20entries%20of%20all%20fonts%20in%20strings.xml
Add android:letterSpacing in PrimaryButton_v2 it will work perfectly.
<style name="ButtonText_v2" parent="TextAppearance.AppCompat">
<item name="fontFamily">#font/silka_regular</item>
<item name="android:textSize">#dimen/dimen_14dp</item>
</style>
<style name="PrimaryButton_v2" parent="Widget.AppCompat.Button">
<item name="android:background">#drawable/button_selector_primary</item>
<item name="android:textColor">#color/white</item>
<item name="textAllCaps">true</item>
<item name="textAppearance">#style/ButtonText_v2</item>
<item name="android:letterSpacing">0.1</item>
</style>
layout.xml File
<Button
android:text="Button"
android:layout_height="56dp"
android:layout_width="200dp"
style="#style/PrimaryButton_v2"
android:layout_margin="15dp"
/>
And my Second Question :
I use a TextInputLayout :
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColorHint="#color/LightBlue"
android:theme="#style/ThemeOverlay.AppTheme.TextInputEditText.Outlined"
app:boxStrokeColor="#color/selector"
app:boxStrokeWidth="3dp"
app:startIconTint="#color/white">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/numberOfPlayer_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:inputType="numberDecimal"
android:textColor="#color/gold" />
</com.google.android.material.textfield.TextInputLayout>
The Styles file
<style name="AppTheme"
parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowBackground">#color/Thistle</item>
<!-- use in get player information -->
<item name="CustomTextStyle">#style/Widget.App. TextInputLayout.
OutlinedBox</item>
</style>
<style name="ThemeOverlay.AppTheme.TextInputEditText.Outlined"
parent="">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="boxCornerRadiusBottomEnd">20dp</item>
<item name="boxCornerRadiusBottomStart">20dp</item>
<item name="boxCornerRadiusTopEnd">20dp</item>
<item name="boxCornerRadiusTopStart">20dp</item>
<item name="android:hint">Number of player</item>
<item name="hintTextColor">#color/card1</item>
<item name="startIconDrawable">#drawable/ic_people</item>
</style>
<style name="Widget.App.TextInputLayout.OutlinedBox"
parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="boxStrokeColor">#color/player_information</item>
<item name="boxCornerRadiusBottomEnd">15dp</item>
<item name="boxCornerRadiusBottomStart">15dp</item>
<item name="boxCornerRadiusTopEnd">15dp</item>
<item name="boxCornerRadiusTopStart">15dp</item>
<item name="android:textColorHint">#color/white</item>
<item name="startIconDrawable">#drawable/player</item>
<item name="startIconTint">#color/gold</item>
<item name="elevation">5dp</item>
<item name="boxStrokeWidth">2dp</item>
<itemname="materialThemeOverlay">#style/ThemeOverlay.App.
TextInputEditText.OutlinedBox</item>
<item name="hintTextColor">#color/AntiqueWhite</item>
<!-- .... -->
</style>
<style name="ThemeOverlay.App.TextInputEditText.OutlinedBox"
parent="ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox">
<!-- to change the cursor color -->
<item name="colorControlActivated">#color/white</item>
</style>
That is my selector file
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/DarkSeaGreen"
android:state_focused="true"/>
<item android:color="#color/white"/>
</selector>
and Attrs
<resources>
<attr name="customTextInputStyle" format="reference" />
<attr name="CustomTextStyle" formet ="reference"/>
</resources>
When I change the version of the material 1.1.0 to 1.3.0 ,The shape of The text input layout1 I created before is distorted. It became wider than it was before. I could not find the reason for this change.As you can see in the picture, the text inputlayout is very wide and the hinttext still looks black on the back.
The main issue is in the ThemeOverlay. You have to add the parent ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox.
<style name="ThemeOverlay.App.TextInputEditText.OutlinedBox" parent="#style/ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox">
<item name="colorPrimary">#color/...</item>
</style>
It is needed because the default style Widget.MaterialComponents.TextInputLayout.OutlinedBox which you are extending has defined a own materialThemeOverlay and
without the parent dependency you are losing the default behaviour.
Also in your xml layout remove android:theme="#style/ThemeOverlay.AppTheme.TextInputEditText.Outlined". You don't need it because you are already using materialThemeOverlay in the style and the theme defined in the xml layout overrides it and this theme overlay is wrong.
Also:
use a min width because you are using a big corner radius 15dp
<com.google.android.material.textfield.TextInputLayout
android:minWidth="150dp"
android:layout_width="wrap_content"
Finally the color used by the hint:
<item name="android:textColorHint">#color/red600Dark</item>
<item name="hintTextColor">#color/teal_700</item>
Final layout:
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.App.TextInputLayout.OutlinedBox"
android:minWidth="150dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:startIconTint="#color/white">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/numberOfPlayer_txt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="numberDecimal"
android:textColor="#color/gold" />
</com.google.android.material.textfield.TextInputLayout>
with:
<style name="Widget.App.TextInputLayout.OutlinedBox"
parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="boxStrokeColor">#color/text_input_stroke_selector</item>
<item name="boxCornerRadiusBottomEnd">15dp</item>
<item name="boxCornerRadiusBottomStart">15dp</item>
<item name="boxCornerRadiusTopEnd">15dp</item>
<item name="boxCornerRadiusTopStart">15dp</item>
<item name="startIconDrawable">#drawable/ic_...</item>
<item name="startIconTint">#color/...</item>
<item name="elevation">5dp</item>
<item name="boxStrokeWidth">2dp</item>
<item name="materialThemeOverlay">#style/ThemeOverlay.App.TextInputEditText.OutlinedBox</item>
<item name="android:textColorHint">#color/....</item>
<item name="hintTextColor">#color/....</item>
</style>
<style name="ThemeOverlay.App.TextInputEditText.OutlinedBox" parent="#style/ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox">
<item name="colorPrimary">#color/....</item>
</style>
There is my app_style.xml
<style name="EditText.LargePassword" parent="Widget.AppCompat.EditText">
<item name="android:gravity">center_horizontal</item>
<item name="android:imeOptions">flagNoExtractUi</item>
<item name="android:inputType">numberPassword</item>
<item name="android:textColorPrimary">#color/white</item>
<item name="android:textColor">#color/white</item>
<item name="android:textColorHint">#color/white</item>
<item name="android:textSize">56sp</item>
<item name="colorControlNormal">#color/white</item>
<item name="colorControlActivated">#color/white</item>
<item name="colorControlHighlight">#color/white</item>
</style>
And part of layout:
<EditText
android:id="#+id/password_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/giant_margin"
android:layout_marginRight="#dimen/giant_margin"
android:theme="#style/EditText.LargePassword"
tools:text="12345"
tools:ignore="TextFields"
/>
As you can see, I apply EditText.LargePassword style via android:theme attribute:
There is a problem: every attribute applied, except android:gravity.
Okay, let's try with style attribute:
style="#style/EditText.LargePassword"
Boom! Indicator and cursor are gone:
But now android:gravity="center_horizontal" works.
As I read, style == theme, but style don't apply to children of View. Are there any differences? Is it a bug?
Styles and Themes whilst similar are not exactly the same. A style applies only to one specific view whereas a theme will apply to a View/ViewGroup/Activity and all of its children.
In your case you are actually mixing attributes from both styles and themes into one setting which is why it's not working properly. To get both you will need to take the three colorControl attributes and define them as a theme:
<style name="LargePasswordTheme" >
<item name="colorControlNormal">#color/white</item>
<item name="colorControlActivated">#color/white</item>
<item name="colorControlHighlight">#color/white</item>
</style>
The rest can stay as a style. Then you can add both this and your style to the EditText:
<EditText
android:id="#+id/password_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/giant_margin"
android:layout_marginRight="#dimen/giant_margin"
android:theme="#style/LargePasswordTheme"
android:style="#style/EditText.LargePassword"
tools:text="12345"
tools:ignore="TextFields"
/>
Further reading with good explanations can be found here and here.
I am facing hard time in changing the color attributes of Floating text Label
My XML Code looks like this:
<android.support.design.widget.TextInputLayout
android:theme="#style/MyMaterialTheme.Base"
android:id="#+id/input_name"
android:layout_below="#+id/tool_bar_first_login"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/edit_input_name"
android:textColorHint="#color/textColorPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/name" />
</android.support.design.widget.TextInputLayout>
My Styles.XML looks like this:
<resources>
<style name="MyMaterialTheme" parent="MyMaterialTheme.Base">
</style>
<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowBackground">#color/windowBackground</item>
<item name="android:textColor">#color/textColorPrimary</item>
<item name="android:textStyle">normal</item>
</style>
</resources>
I want to change the text color, hint text color, edit box Line color when not selected and edit box line color when selected.
I am unable to change colors.
Dears,
I want to achieve the following design:
Problems:
Unable to set padding for the hint text inside the EditText.
Code:
<EditText
style="#style/txtBoxStyle"
android:id="#+id/txtUsername"
android:drawableLeft="#drawable/ic_username"
android:hint="#string/text_username">
</EditText>
Style:
<style name="txtBoxStyle">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">#drawable/edittext_rounded_corners</item>
<item name="android:paddingLeft">20dp</item>
<item name="android:ems">10</item>
</style>
Can't add icon for the spinner on the left side.
Code:
<Spinner
style="#style/ddlStyle"
android:id="#+id/lstCountry"/>
Style:
<style name="ddlStyle" parent="#android:style/Widget.Spinner">
<item name="android:layout_width">fill_parent</item>
<item name="android:background">#android:drawable/ic_country</item>
<item name="android:layout_height">32dp</item>
<item name="android:background">#drawable/edittext_rounded_corners</item>
<item name="android:spinnerMode">dialog</item>
<item name="android:drawableLeft">#drawable/ic_country</item>
</style>
Can't align the image and text inside the button to center.
Please Help.
To give padding between your image and hint text you should have to use android property
android:drawablePadding="10dp"