textSize in Radio Buttons doesn't follow defined style - android

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.

Related

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>

Can't inherit button color on style

I am trying to define button properties on style.
My code is
<style name="button">
<item name="android:paddingTop">5dp</item>
<item name="android:paddingBottom">5dp</item>
<item name="android:textAllCaps">false</item>
<item name="colorButtonNormal">#f37022</item>
<item name="android:textColor">#ffffff</item>
</style>
And using as
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Prepaid Package"
style="#style/button"/>
But the color of the button's normal state is not changing.
This button style is only for some buttons. Not for all butons.
What to do now?
edit after question clarification
Save you style.xml in res/values/
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="custom_button" parent="#android:style/Widget.Button">
<item name="android:paddingTop">5dp</item>
<item name="android:paddingBottom">5dp</item>
<item name="android:textAllCaps">false</item>
<item name="colorButtonNormal">#f37022</item>
<item name="android:textColor">#ffffff</item>
</style>
Apply it like so:
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Prepaid Package"
style="#style/custom_button"/>
first answer
You need to inherit the parent style.
<style name="Button" parent="#android:style/Widget.Button">
<item name="android:paddingTop">5dp</item>
<item name="android:paddingBottom">5dp</item>
<item name="android:textAllCaps">false</item>
<item name="colorButtonNormal">#f37022</item>
<item name="android:textColor">#ffffff</item>
</style>
That way all your Button's that are not styled will have your custom style. i.e. no need to put in the style value.
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Prepaid Package"/>

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"

applying style to textview drawable

I have a layout for a TextView and drawable as such...
<LinearLayout style="#style/dashboard_content_horizontal" >
<ImageView
style="#style/dashboard_imageview"
android:src="#drawable/menu6" />
<TextView
style="#style/dashboard_textview"
android:text="#string/menu6_text />
</LinearLayout>
as you can see the image uses a style attribute which looks like this
<style name="dashboard_imageview">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:layout_weight">1</item>
<item name="android:scaleType">fitCenter</item>
</style>
the linear layout's style surrounding it looks like this
<style name="dashboard_content_horizontal">
<item name="android:layout_width">0px</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:layout_weight">3</item>
<item name="android:orientation">vertical</item>
<item name="android:layout_gravity">center</item>
<item name="android:gravity">center</item>
</style>
and TextView's style
<style name="dashboard_textview">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:gravity">center</item>
<item name="android:textSize">20sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#color/black</item>
</style>
this all works and looks exactly how I want it to look. however, because of this eclipse warning
"This tag and its children can be replaced by one
and a compound drawable" I decide to try to do this with just a TextView and drawable
like such..
<TextView
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Menu6"
android:drawableBottom="#drawable/my_drawable"
android:padding="5dp" />
this renders the image too small.. I don't see a way to apply a style to the image to get it like I want it.. anyone know the answer? is even possible?

EditText/Spinner/Button special style in 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"

Categories

Resources