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.
Related
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"
/>
I think this is an easy question, but I haven't been able to find an answer to my specific problem.
I've read this great article and would like to set the background color of the selected item on the Android Dropdown list on the stock ActionBar (I'm not using Sherlock and I'm targetting ICS+), as explained in the image link below:
So far I've set my theme in this way:
<resources>
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<item name="android:dropDownListViewStyle">#style/MyDropDownListView</item>
</style>
<style name="MyDropDownListView" parent="android:style/Widget.Holo.ListView.DropDown">
<item name="android:listSelector">#drawable/ad_selectable_background</item>
</style>
</resources>
And this is my ad_selectable_background.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="#android:integer/config_mediumAnimTime" >
<item android:state_pressed="true" android:drawable="#android:color/holo_blue_light" />
<item android:drawable="#android:color/transparent" />
</selector>
My dropdown view resource is:
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
The pressed state works, but when you open the menu no selection is displayed.
I would like to set it to holo_blue_light using the selector, but I'm not able to find the correct syntax using XML.
I'm looking for an XML only answer if it's possible (i.e. not using any code). Thanks!
Apparently, it was quite simple!
I had to edit ad_selectable_background.xml to use the checked state (as I did before, but I was missing the theme below):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="#android:integer/config_mediumAnimTime" >
<item android:state_pressed="false" android:state_checked="true" android:drawable="#android:color/holo_blue_light" />
<item android:state_pressed="true" android:drawable="#android:color/holo_blue_light" />
<item android:drawable="#android:color/transparent" />
</selector>
And then edit the theme by adding the android:spinnerDropDownItemStyle item and disabiling the checkMark (as I didn't want the radio buttons), in this way:
<resources>
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<item name="android:dropDownListViewStyle">#style/MyDropDownListView</item>
<item name="android:spinnerDropDownItemStyle">#style/MySpinnerDropDownItem</item>
</style>
<style name="MyDropDownListView" parent="android:style/Widget.Holo.ListView.DropDown">
<item name="android:listSelector">#drawable/ad_selectable_background</item>
</style>
<style name="MySpinnerDropDownItem" parent="android:style/Widget.DropDownItem.Spinner">
<item name="android:background">#drawable/ad_selectable_background</item>
<item name="android:checkMark">#null</item>
</style>
</resources>
I created a customer spinner and don't get rid of white spaces when the popup appears:
That's how I created the custom spinner:
I copied simple_spinner_dropdown_item.xml and simple_spinner_item.xml from installation directory to my layout folder and changed the style attributes so that they point to my own style:
simple_spinner_item.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
...
style="#style/spinnerItemStyle" />
simple_spinner_dropdown_item.xml
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
...
style="#style/spinnerDropDownItemStyle" />
spinnerItemStyle.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="spinnerItemStyle" parent="android:Widget.TextView.SpinnerItem">
<item name="android:textColor">#FFF</item>
<item name="android:textSize">12sp</item>
<item name="android:background">#null</item>
</style>
</resources>
spinnerDropDownItemStyle.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="spinnerDropDownItemStyle" parent="android:TextAppearance.Widget.DropDownItem">
<item name="android:textColor">#FFF</item>
<item name="android:padding">20dp</item>
<item name="android:textSize">12sp</item>
<item name="android:background">#drawable/spinner_rectangle</item>
</style>
</resources>
spinner_rectangle.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#333" />
<stroke
android:width="0dip" />
</shape>
The spinner is simply referenced within the layout file of the Activity:
<Spinner
android:id="#+id/preferences_spinner_language"
android:background="#drawable/spinner_dropdown" />
And I don't use a custom Adapter, just the usual ArrayAdapter where I use the both resources from above and not the Android resources:
Spinner spinner = (Spinner)findViewById(R.id.preferences_spinner_language);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.preferences_language_array, R.layout.simple_spinner_item);
adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
I guess that there is some underlying ImageView which produces these white borders. How can I access it and get rid of these border or colorize them? I would prefer a solution where I don't have to create an own ArrayAdapter.
In your theme, override the android:dropDownListViewStyle style. Eg:
<style name="AppTheme" parent="#android:style/Theme.Holo">
<item name="android:dropDownListViewStyle">#style/MySpinnerStyle</item>
</style>
<style name="MySpinnerStyle" parent="android:style/Widget.ListView.DropDown">
<item name="android:divider">#FFEEEEEE</item>
<item name="android:dividerHeight">1dp</item>
</style>
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'
I made a custom 9-patch images for my button's background. Buttons are in drawable-hdpi and drawable-mdpi folder. I created custom selector file for my button states.
selector file login_button.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Image display in background in select state -->
<item android:state_pressed="true" android:drawable="#drawable/login_button_down" />
<!-- Image display in background in select state -->
<item android:state_focused="true" android:drawable="#drawable/login_button_down" />
<!-- Default state -->
<item android:drawable="#drawable/login_button" />
</selector>
Then I made a custom styles.xml file for the button style:
<style name="login_button_style" parent="#android:style/Widget.Button">
<item name="android:gravity">center_vertical|center_horizontal</item>
<item name="android:textColor">#FF000000</item>
<item name="android:shadowColor">#FFFFFFFF</item>
<item name="android:shadowDx">0</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">0.2</item>
<item name="android:textSize">13dp</item>
<item name="android:textStyle">bold</item>
<item name="android:background">#drawable/login_button</item>
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
</style>
Then applied this style to my theme file in themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="customTheme" parent="#android:style/Theme.NoTitleBar" >
<item name="android:editTextStyle">#style/login_edittext_style</item>
<item name="android:buttonStyle">#style/login_button_style</item>
<item name="android:textViewStyle">#style/login_textview_style</item>
</style>
</resources>
And finally added button itself to the layout file:
<Button
android:text="#string/login_text"
android:id="#+id/buttonSignIn"
android:layout_width="130dp"
android:layout_height="wrap_content">
</Button>
But if I click the button, then background image is not changed. Code is ok and all compiles nicely. I know that I have same image for two different states, but it doesn't work even for one state in emulator. Can anyone point me where is the problem?
EDIT:
Obviously normal state is working, because it gets it's image from selector xml file. Now i'm wondering why the other states are not...
I thought maybe is something to do with naming, so I named button state images with different name than login_button, because selector xml file has the same name. And I edited my selector xml file also.
Selector xml file:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Image display in background in select state -->
<item android:state_pressed="true" android:drawable="#drawable/login_btn_down" />
<!-- Image display in background in select state -->
<item android:state_focused="true" android:drawable="#drawable/login_btn_down" />
<!-- Default state -->
<item android:drawable="#drawable/login_btn" />
</selector>