EditText/Spinner/Button special style in Android - android

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"

Related

How to apply letter spacing in custom button?

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"
/>

TextInputEditText top of text input cut off android

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

set a custom font for a button text in Xamarin Android

I have a button and I want to set a custom font to the text but I have trouble doing that.
The code is the following :
In .xml file :
<Button
android:id="#+id/button"
style="#style/ButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Sample Text"/>
and in styles.xml
<style name="ButtonStyle" parent="#style/Widget.AppCompat.Button.Borderless">
<item name="android:textSize">#dimen/button_text_size</item>
<item name="android:background">#drawable/button_background</item>
<item name="android:textAppearanceButton">#style/ButtonTextStyle</item>
<item name="android:textColor">?android:textColorPrimaryInverse</item>
</style>
<style name="ButtonTextStyle" parent="TextAppearance.AppCompat">
<item name="android:fontFamily">#font/my_custom_font</item>
</style>
Instead of of creating a different style fontFamily should be used in the button style and the code should look like this.
<style name="ButtonStyle" parent="#style/Widget.AppCompat.Button.Borderless">
<item name="android:textSize">#dimen/button_text_size</item>
<item name="android:background">#drawable/button_background</item>
<item name="android:fontFamily">#font/my_custom_font</item>
<item name="android:textColor">?android:textColorPrimaryInverse</item>
</style>

textSize in Radio Buttons doesn't follow defined style

In my layout there are two styles defined for two different elements: a headline (upper) and radio buttons. They both should have textSize of 30sp in sw600dp and wider layouts; this is how it looks in their styles:
<item name="android:textSize">30sp</item>.
In the meantime, they look like:
How can I make the radio button text become bigger?
EDIT: adding styles & code of both elements.
1a. Headline code:
<TextView
android:id="#+id/question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:text="#string/q1_question"
style="#style/headlineTextView"/>
1b. Headline style:
-- parent:
<style name="textViewParent">
<item name="android:typeface">sans</item>
<item name="android:textColor">#color/darkest_gray</item>
</style>
-- child:
<style name="headlineTextView" parent="textViewParent">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginRight">0dp</item>
<item name="android:textStyle">italic</item>
<item name="android:textSize">30sp</item>
<item name="android:textColor">#color/darkest_gray</item>
<item name="android:layout_gravity">center_vertical</item>
<item name="android:layout_marginLeft">40dp</item>
</style>
2a. Radio Button code:
<RadioButton
android:id="#+id/qf2e_radio_ans0"
android:text="#string/desc_flag_0"
style="#style/quizRadioButton" />
2b. Radio Button style:
-- no-parent:
<style name="quizRadioButton">
<item name="android:layout_height">match_parent</item>
<item name="android:minHeight">40dp</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:textColor">#color/darkest_gray</item>
<item name="android:textSize">30sp</item>
<item name="android:layout_marginBottom">20dp</item>
</style>
The buttons are grouped under RadioGroup.
It is a good idea to make your standard widget's styles inherit the standard styles. For example, your radio button style should look like:
<style name="quizRadioButton" parent="#android:style/Widget.CompoundButton.RadioButton">
Once you do that, the textSize attribute will work.

textAppearance not work in TextView

I show linked text in TextView.
At beginning , My code like this:
<TextView
style="#style/informed_consent_check_TextView"
android:id="#+id/accept_content_1"
android:text="#string/informed_consent_accept"
/>
<style name="informed_consent_check_TextView" >
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">13dp</item>
<item name="android:textColor">#fff</item>
<item name="android:textColorLink">#fff000</item>
</style>
It works alright.The link text display like this:
That's what I want.
However , after I move attributes about text into a style . It works wrong.
<style name="informed_consent_content_textAppearance">
<item name="android:textSize">13dp</item>
<item name="android:textColor">#fff</item>
<item name="android:textColorLink">#fff000</item>
</style>
<style name="informed_consent_check_TextView" >
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textAppearance">#style/informed_consent_content_textAppearance</item>
</style>
The link text display the wrong color:
And then , I move the textAppearance attribute into TextView. But it still wrong.
<TextView
style="#style/informed_consent_check_TextView"
android:id="#+id/accept_content_1"
android:text="#string/informed_consent_accept"
android:textAppearance="#style/#style/informed_consent_content_textAppearance"/>
My device is 4.1.2 .
Who can help me . Thanks a lot.
make change in textview attribute
android:textAppearance = "#style/informed_consent_content_textAppearance"

Categories

Resources