styling in text (textView) - android

Android,How to do styling in textView . I want to style the text of textView, i am trying style for textView (text) border means suppose i have written "HELLO" in white color and font is bold so,now i want to make a border (style) on "HELLO" with red color but i don't understand how to do that ? I tried a lot but it won't work as i want it and there are so many errors in my code ...Please help me ..!
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:capitalize">characters</item>
<item name="android:textSize">12pt</item>
<item name="android:textColor">#ffffff</item>/>
<item name="android:textborderColor">#ff00ff</item>
</style>
</resources>

you can use style like this , In style xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="newtextview" parent="Widget.AppCompat.Textview">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:capitalize">characters</item>
<item name="android:textSize">12pt</item>
<item name="android:textColor">#ffffff</item>/>
<item name="android:textborderColor">#ff00ff</item>
</style>
</resources>
and use like this :
<Textview
android:id="#+id/tv"
style="#style/edt_text"
android:textColor="#616161"
/>

Related

Make TabView background fill whole tab

Here is where I am right now: screenshot of problem.
Ignoring the tab indicator (which I will figure out later) the problem I'm having is the background I set for the selected tab seems to only be filling the text of the tab.
I would like for the tab selected background to fill the selected tab, and not just the text.
Here's what I've done so far:
res/values/themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/bg_action_bar</item>
</style>
<style name="LoginActionBar"
parent="#style/MyActionBar">
<item name="android:actionBarTabStyle">#style/LoginActionBarTabs</item>
</style>
<style name="LoginActionBarTabs"
parent="#android:style/Widget.Holo.ActionBar.TabView">
<item name="android:background">#drawable/login_actionbar_tab_indicator</item>
<item name="android:padding">0dp</item>
</style>
</resources>
res/drawable/login_actionbar_tab_indicator.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_selected="false"
android:drawable="#color/loginTab" />
<item android:state_selected="true"
android:drawable="#color/loginTabSelected" />
</selector>
res/values/colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="loginTabSelected">#FFFFFF</color>
<color name="loginTab">#999999</color>
</resources>
You can put the TextView as matchparent for height and width and use your selector for its background.

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"

Give text of selected tab a different color using ViewPagerIndicator

I've tried to let the SampleTabsStyled demo from the ViewPagerIndicator change the color of the text of the currently selected tab without success.
However, the SampleTitlesStyledTheme demo does change its text color when switching between titles/tabs.
When looking inside the styles xml:
<resources>
...
<style name="CustomTitlePageIndicator">
<item name="android:background">#18FF0000</item>
<item name="footerColor">#FFAA2222</item>
<item name="footerLineHeight">1dp</item>
<item name="footerIndicatorHeight">3dp</item>
<item name="footerIndicatorStyle">underline</item>
<item name="android:textColor">#AA000000</item>
<item name="selectedColor">#FF000000</item>
<item name="selectedBold">true</item>
</style>
...
<style name="CustomTabPageIndicator" parent="Widget.TabPageIndicator">
<item name="android:background">#drawable/custom_tab_indicator</item>
<item name="android:textAppearance">#style/CustomTabPageIndicator.Text</item>
<item name="android:textColor">#FF555555</item>
<item name="android:textSize">16sp</item>
<item name="android:divider">#drawable/custom_tab_indicator_divider</item>
<item name="android:dividerPadding">10dp</item>
<item name="android:showDividers">middle</item>
<item name="android:paddingLeft">8dp</item>
<item name="android:paddingRight">8dp</item>
<item name="android:fadingEdge">horizontal</item>
<item name="android:fadingEdgeLength">8dp</item>
</style>
<style name="CustomTabPageIndicator.Text" parent="android:TextAppearance.Medium">
<item name="android:typeface">monospace</item>
</style>
...
</resources>
I see that the SampleTitlesStyledTheme demo uses the CustomTitlePageIndicator style, which defines a selectedColor item. So (perhaps naively) I thought to add
<item name="selectedColor">#FF000000</item>
to the style the SampleTabsStyled demo is using, CustomTabPageIndicator, but, alas, that didn't work.
The question seems obvious, but I'll ask anyway: is there a way (using the present styles xml) to let the currently selected text of a tab in the SampleTabsStyled demo have a different color than the other tabs? If so, how?
EDIT
Oh, and I'm using this in combination with ActionBarSherlock, in case that is important...
Assuming you don't mind creating an extra xml, first try include the attribute android:textColor in your CustomTabPageIndicator.Text (or CustomTabPageIndicator) like this:
<style name="CustomTabPageIndicator.Text" parent="android:TextAppearance.Medium">
<item name="android:textColor">#drawable/tab_text_color</item>
...
</style>
where tab_text_color.xml is put under res/drawable folder:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="true"
android:color="#color/text_tab_selected" />
<item
android:state_selected="false"
android:color="#color/text_tab_unselected" />
</selector>
Finally, just define the two colors #color/text_tab_selected and #color/text_tab_unselected in your color resource file colors.xml located in res/values folder (create one if it does not exist already). For example:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="text_tab_selected">#FF000000</color>
<color name="text_tab_unselected">#FF555555</color>
</resources>
Try this
Simplest way
<android.support.design.widget.TabLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabTextColor="#color/White"
app:tabSelectedTextColor="#color/Blue"
app:tabIndicatorColor="#color/Yellow"
app:tabMode="fixed"
app:tabGravity="fill"/>
Don't forgot to add this Dependency
compile 'com.android.support:design:23.1.1'

Textview: using the dialog title style: #android:style/TextAppearance.DialogWindowTitle

I am currently trying tu build my own DialogFragment theme.
One of my requirement is to use an icon at the right of the title.
First idea
Simply using:
this.getDialog().getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.dialog_title);
But unfortunately, this line of code has no result.
Second idea
Provinding my own layout -this.setContentView()- with this textview:
<TextView
android:id="#+id/tvTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="From XML"
android:textAppearance="#android:style/TextAppearance.DialogWindowTitle" />
This works, because I can read the text, but it still written in default black font.
I was expecting TextAppearance.DialogWindowTitle to give my text a title appareance (blue in Holo with big font size)
Any idea or suggestion?
EDIT
This nearly did the trick:
<style name="Dialog" parent="#android:style/Theme.Dialog">
<item name="android:windowTitleStyle">#style/MyOwnDialogTitle</item>
</style>
<style name="MyOwnDialogTitle">
<item name="android:drawableRight">#drawable/MyRightImage</item>
</style>
but android:drawableRight just broke the title layout:
SECOND EDIT
This is a little bit better:
<style name="Dialog" parent="#android:style/Theme.Dialog">
<item name="android:windowTitleStyle">#style/MyOwnDialogTitle</item>
</style>
<style name="MyOwnDialogTitle">
<item name="android:textAppearance">#android:style/TextAppearance.DialogWindowTitle</item>
<item name="android:drawableRight">#drawable/icon</item>
</style>
Maybe you can extend the default style in this manner:
res/values/dialogstyles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Dialog" parent="#android:style/Theme.Dialog">
<item name="android:windowTitleStyle">#style/MyOwnDialogTitle</item>
</style>
<style name="MyOwnDialogTitle">
<item name="android:drawableRight">#drawable/MyRightImage</item>
</style>
</resources>
res/values-v11/dialogstyles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Dialog" parent="#android:style/Theme.Holo.Dialog">
<item name="android:windowTitleStyle">#style/MyOwnDialogTitle</item>
</style>
</resources>
And override your DialogFragment's onCreate:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.style.Dialog);
}
Working Example
I am searching for your first requirement. but for second requirement, why dont you try with changing the color to style of the TextAppearance.DialogWindowTitle with your custom style ?
I have just check the android resources where there is style like below:
<style name="DialogWindowTitle">
<item name="android:maxLines">1</item>
<item name="android:scrollHorizontally">true</item>
<item name="android:textAppearance">#style/TextAppearance.DialogWindowTitle</item>
</style>
and for TextAppearance.DialogWindowTitle style:
<style name="TextAppearance.DialogWindowTitle">
<item name="android:textSize">18sp</item>
<item name="android:textStyle">normal</item>
<item name="android:textColor">?textColorPrimary</item>
</style>
Now, you can change the color of your TextAppearance.DialogWindowTitle style and do as you want.
Hope you got the point.
Feel free to comment.
Have you tried to use #android:style/Theme.Holo.Light.Dialog as your parent in styles? This will work only in Android 3+ because in earlier version there is no theme Holo, but you can create your own to look like it for lower versions of Android.

Switching Styles

Let's say I have multiple styles.xml files (with different names of course) for themes. Is it possible to choose which file the app should pull from?
White style:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="mybutton">
<item name="android:layout_width">45dp</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:textColor">#202020</item>
<item name="android:textSize">20dp</item>
<item name="android:textStyle">bold</item>
<item name="android:background">#drawable/white_btnbg</item>
</style>
...
Black style:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="mybutton">
<item name="android:layout_width">45dp</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:textSize">20dp</item>
<item name="android:textStyle">bold</item>
<item name="android:background">#drawable/black_btnbg</item>
</style>
...
So then, in my layout xml all my button's styles would be set to "mybutton" and depending which theme the user chose it would pull from the coordinating file.
Since it isn't possible to change a view's style at runtime is it possible to do this? Or is there a better way (i'm sure there is) to change styles?
Use multiple styles with different names. Then you can set the backGround programmatically:
Button b = new Button(this);
b.setBackgroundResource(R.drawable.blabla);

Categories

Resources