textAppearance not work in TextView - android

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"

Related

How to change to text color of all the button in my app?

How can i change the text color of all the button in my app ? right now the only think that work is to do :
<style name="MyTheme" parent="#android:style/Theme.Material.Light.NoActionBar">
<item name="android:textColor">#ff0000</item>
</style>
but i m a little worried to use android:textColor who seam to not only impact the button
I try this but it's didn't work :
<style name="BBButtonColor" parent="#android:style/Widget.Button">
<item name="android:textColor">#ff0000</item>
</style>
<style name="BBButtonStyle" parent="#android:style/Widget.Button">
<item name="android:textColor">#ff0000</item>
</style>
<style name="BBBorderlessButtonStyle" parent="#android:style/Widget.Button">
<item name="android:textColor">#ff0000</item>
</style>
<style name="MyTheme" parent="#android:style/Theme.Material.Light.NoActionBar">
<item name="android:textAppearanceButton">#style/BBButtonColor</item>
<item name="android:buttonStyle">#style/BBButtonStyle</item>
<item name="android:borderlessButtonStyle">#style/BBBorderlessButtonStyle</item>
<item name="android:colorButtonNormal">#ff0000</item>
</style>
It's mostly the color of button inside popup dialog that i want to change
Loki, you can try this. This should change the color of all buttons in your app.
<style name="BBButtonColor" parent="android:Widget.Button">
<item name="android:textColor">#FF0000</item>
</style>
You were trying to use #android:style/Widget.Button, instead use android:Widget.Button and check. Let me know if this works.
You can try this :
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:buttonStyle">#style/ButtonColor</item>
<item name="colorButtonNormal">#color/colorname</item>
</style>
<style name="ButtonColor" parent="#android:style/Widget.Button">
<item name="android:textColor">#color/colorname</item>
</style>
and/change this line in Manifest file :
android:theme="#style/AppTheme.Base
You should create new style for buttons, something like that:
<style name="optionsButton">
<item name="android:layout_width">70dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">#color/white</item>
<item name="android:textColor">#color/black</item>
<item name="android:textSize">15sp</item>
</style>
Now you can set this style for every button you want in layout xml, for example:
<Button
android:id="#+id/payCashBtn"
style="#style/optionsButton"
android:text="Cash" />
You can see I set layout_width and height in style, so all my buttons which use this style will have same parameters, but you can set different values for every button, or create multiple styles if you used it more than once. I hope it will help you.

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"

How to change default color in all texts in my Android application?

I would like to change all color texts in my application.
So I wrote this code and I set my theme in the manifest:
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:textColor">#color/white</item>
</style>
But only TextView texts are in white. I would like Button and EditText to be in white too.
Can anyone help me? Thank you in advance.
Your Theme:
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:textColor">#color/white</item>
<item name="android:buttonStyle">#style/ButtonTheme</item>
</style>
And this is how you can set your Button Theme:
<style name="ButtonTheme" parent="android:style/Widget.Button">
<item name="android:textColor">#color/white</item>
</style>
And also do this with EditTexts etc.
I think most of the widget styles build off of these:
<item name="android:textColorPrimary">#android:color/primary_text_dark</item>
<item name="android:textColorSecondary">#android:color/secondary_text_dark</item>
<item name="android:textColorTertiary">#android:color/tertiary_text_dark</item>
<item name="android:textColorPrimaryInverse">#android:color/primary_text_light</item>
<item name="android:textColorSecondaryInverse">#android:color/secondary_text_light</item>
<item name="android:textColorTertiaryInverse">#android:color/tertiary_text_light</item>
<item name="android:textColorPrimaryDisableOnly">#android:color/primary_text_dark_disable_only</item>
<item name="android:textColorPrimaryInverseDisableOnly">#android:color/primary_text_light_disable_only</item>
<item name="android:textColorPrimaryNoDisable">#android:color/primary_text_dark_nodisable</item>
<item name="android:textColorSecondaryNoDisable">#android:color/secondary_text_dark_nodisable</item>
<item name="android:textColorPrimaryInverseNoDisable">#android:color/primary_text_light_nodisable</item>
<item name="android:textColorSecondaryInverseNoDisable">#android:color/secondary_text_light_nodisable</item>
<item name="android:textColorHint">#android:color/hint_foreground_dark</item>
<item name="android:textColorHintInverse">#android:color/hint_foreground_light</item>
<item name="android:textColorSearchUrl">#android:color/search_url_text</item>
Override the values as needed.
Assign color to button text
<Button android:textColor="#FFFFFF"></Button>

How we add styles programmatically?

I have written one style for TextView and I set that one for my TextView as style="#style/popup_window_text_style" working fine, no issues.
Now I want that same style to do in programmatically for my textview
TextView textView = new TextView(mContext);
Is there any way to do it programmatically in Java?
My style in styles.xml
<style name="popup_window_text_style">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:minWidth">60dp</item>
<item name="android:padding">10dp</item>
<item name="android:layout_marginLeft">1dp</item>
<item name="android:layout_marginRight">1dp</item>
<item name="android:background">#drawable/ctxmenu_btn_selector</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">16sp</item>
<item name="android:gravity">center_vertical</item>
<item name="android:singleLine">true</item>
</style>
This should work for you:
textView.setTextAppearance(getApplicationContext(), R.style.popup_window_text_style);
But note that some properties may not be affected and may have to be set manually as specified in the Android developer docs.
Unfortunately the current SDK appears to lack any form of a setStyle() method.

Android Set ImageView image src in Style

I need to set the ImageView's src within my style, but I cant find a good example of anyone doing this and when I try the below code, it crashes the app.
<ImageView android:src="#style/TitleBarImage"></ImageView>
<style name="TitleBarImage">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:src">#drawable/whiteButton</item>
</style>
This should be simple. What gives?
Your xml is incorrect:
<ImageView style="#style/TitleBarImage" />
And styles.xml :
<style name="TitleBarImage">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:src">#drawable/whiteButton</item>
</style>

Categories

Resources