Does anyone know what is the location of Holo theme focused button drawable? I would like to set it to my View on some event, but I can't find it.
1.first locate following location in your android sdk platforms folder -
yourandroidsdkrootfolderpath\platforms\android-11\data\res\drawable
(ex:D:\android\platforms\android-11\data\res\drawable)
2.find the xml file on folder named as btn_default_holo_dark.xml
and it's contain like below code:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="#drawable/btn_default_normal_holo_dark" />
<item android:state_window_focused="false" android:state_enabled="false"
android:drawable="#drawable/btn_default_normal_disable_holo_dark" />
<item android:state_pressed="true"
android:drawable="#drawable/btn_default_pressed_holo_dark" />
<item android:state_focused="true" android:state_enabled="true"
android:drawable="#drawable/btn_default_selected_holo_dark" />
<item android:state_enabled="true"
android:drawable="#drawable/btn_default_normal_holo_dark" />
<item android:state_focused="true"
android:drawable="#drawable/btn_default_normal_disable_focused_holo_dark" />
<item
android:drawable="#drawable/btn_default_normal_disable_holo_dark" />
</selector>
3.copy xml to your project drawable folder
4.copy drawable-hdpi,drawable-ldpi,drawable-mdpi images mentioned above xml like
btn_default_normal,btn_default_normal_disable,btn_default_pressed,btn_default_selected,btn_default_normal,btn_default_normal_disable_focused,btn_default_normal_disable
5.add style to your style.xml file like below
<style name="Custombutton" parent="Widget.Button">
<item name="android:background">#android:drawable/btn_default_holo_dark</item>
<item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
<item name="android:textColor">#android:color/primary_text_holo_dark</item>
<item name="android:minHeight">48dip</item>
<item name="android:minWidth">64dip</item>
</style>
6.apply your button style like below code:
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
style="#style/Custombutton"
android:layout_height="wrap_content"
android:text="Button" />
Hdpi versions:
/<android sdk path>/platforms/android-15/data/res/drawable-hdpi/btn_default_disabled_holo.9.png
/<android sdk path>/platforms/android-15/data/res/drawable-hdpi/btn_default_focused_holo.9.png
/<android sdk path>/platforms/android-15/data/res/drawable-hdpi/btn_default_normal_holo.9.png
/<android sdk path>/platforms/android-15/data/res/drawable-hdpi/btn_default_pressed_holo.9.png
other resolutions are in drawable-ldpi,drawable-mdpi,drawable-xhdpi directories.
Related
I want to make a menu on my app's top like which showed me in the AS's xml, but in Android 6.0,it's on the bottom. How can I solve this problem? Thanks.
I have tried many methods like change my code, add the android:showAsAction='always', but it doesn't work.
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/menu_new_folder"
android:title="#string/menu_create_folder" />
<item
android:id="#+id/menu_export_text"
android:title="#string/menu_export_text"/>
<item
android:id="#+id/menu_sync"
android:title="#string/menu_sync"/>
<item
android:id="#+id/menu_setting"
android:title="#string/menu_setting" />
<item
android:id="#+id/menu_search"
android:title="#string/menu_search"/>
Create menu like this -
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/action_more"
android:orderInCategory="1"
android:icon="#drawable/ic_menu_dots"
android:title="more"
app:showAsAction="always">
<menu>
<item
android:id="#+id/menu_new_folder"
android:title="#string/menu_create_folder" />
<item
android:id="#+id/menu_export_text"
android:title="#string/menu_export_text"/>
<item
android:id="#+id/menu_sync"
android:title="#string/menu_sync"/>
<item
android:id="#+id/menu_setting"
android:title="#string/menu_setting" />
<item
android:id="#+id/menu_search"
android:title="#string/menu_search"/>
</menu>
</item>
</menu>
And in your activity's onCreateOptionMenu add this -
menu.findItem(R.id.action_more).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
I am trying to set custom color for Tab text in one of my android application but instead change its setting white color for it. Other tab text is going changed but not changing only for selected Tab.
My Style for Tab is like below
<style name="MineCustomTabText"
parent="TextAppearance.Design.Tab">
<item name="tabSelectedTextColor">#000</item>
<item name="android:textColor">#color/TextColorLite</item>
<item name="android:textSize">#dimen/textPageCount</item>
</style>
I am using it in My Layout XML is like below
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
app:tabGravity="fill"
app:tabTextAppearance="#style/MineCustomTabText"
app:tabMode="fixed"
android:layout_height="wrap_content" />
You can see I have set black color for selected tab in style but its showing only white color. Let me know what I am missing. Thanks
Try this following code:
Add this style into your TabLayout
<android.support.design.widget.TabLayout
style="#style/MyCustomTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Add this style into your Style.xml
<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
<!--<item name="tabMaxWidth">#dimen/tab_max_width</item>-->
<item name="tabIndicatorColor">#color/appcolor</item>
<item name="tabIndicatorHeight">2dp</item>
<item name="tabPaddingStart">10dp</item>
<item name="tabPaddingEnd">10dp</item>
<item name="tabBackground">#color/lightblue</item>
<item name="tabTextAppearance">#style/MyCustomTabTextAppearance</item>
<item name="tabSelectedTextColor">#color/appcolor</item>
</style>
<style name="MyCustomTabTextAppearance" parent="TextAppearance.Design.Tab">
<item name="android:textSize">15sp</item>
<item name="android:textColor">#color/black</item>
<item name="textAllCaps">true</item>
</style>
Another way to change programmatically:
tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#FF0000"));
tabLayout.setSelectedTabIndicatorHeight((int) (5 * getResources().getDisplayMetrics().density));
tabLayout.setTabTextColors(Color.parseColor("#727272"), Color.parseColor("#ffffff"));
I hope this will help you
Add tab_text_color.xml in drawable folder like below
<?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>
then in style.xml do this and check
<style name="CustomTabPageIndicator.Text" parent="android:TextAppearance.Medium">
<item name="android:textColor">#drawable/tab_text_color</item>
...
</style>
I am trying to create a custom rating bar where number of stars is dynamic and the drawable that I need to use also depends on the type, that I get from server.
I am doing this -
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:id="#+id/rating_bar_star"
android:layout_gravity="center"
style="#style/RatingBarStar"
android:stepSize="0.1"/>
then I added this in style -
<style name="RatingBarStar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/rating_bar</item>
<item name="android:minHeight">20dip</item>
<item name="android:maxHeight">20dip</item>
</style>
this is my rating_bar.xml I added in drawable -
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background"
android:drawable="#drawable/rating_bar_empty" />
<item android:id="#android:id/secondaryProgress"
android:drawable="#drawable/rating_bar_empty" />
<item android:id="#android:id/progress"
android:drawable="#drawable/rating_bar_filled" />
</layer-list>
rating_bar_empty.xml
<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="#drawable/rating_off" />
<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="#drawable/rating_off" />
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="#drawable/rating_off" />
<item android:drawable="#drawable/rating_off" />
and rating_bar_filled.xml -
<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="#drawable/rating_on" />
<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="#drawable/rating_on" />
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="#drawable/rating_on" />
<item android:drawable="#drawable/rating_on" />
and then added this in my java file -
rating_bar_star.setNumStars(getStars());
Obviously I am getting stars from server. Now my problem is when I click/select a star it doesn't select one whole star.
If number of star is 6 and I set stepSize as 0.8 then it works fine but same stepSize doesn't work for 10 stars. All I want, my stars to show selected appearance for selected stars.
this is what I get when I don't set stepSize and select/click on first star
and this when I click on second -
I would like to know how to change the image of a switch in android. I know that we can customize the switch and change the color etc. but how do we use another image for the switch. I tried setting the background from my drawables but the switch is still visible and appears on top of my image. I understand that we can use toggle button, or image button however I am curious if we can do so to a switch.
Override android:thumb and android:track in Switch component to override switch image and background respectiveli.
For eg:
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:thumb="#drawable/drawable_switch"
android:track="#drawable/drawable_bg" />
where drawable_switch and drawable_bg are selectors respectively.
drawable_switch.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="#drawable/switch_disabled" />
<item android:state_pressed="true" android:drawable="#drawable/switch_pressed" />
<item android:state_checked="true" android:drawable="#drawable/switch_enabled" />
<item android:drawable="#drawable/switch_default" />
drawable_bg.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="#drawable/switch_bg_disabled" />
<item android:state_focused="true" android:drawable="#drawable/switch_bg_focused" />
<item android:drawable="#drawable/switch_bg_default" />
#Jerry try this and revert if you still have any issues
There's android:thumb attribute.
I use this in my Radio Buttons so the text will be on the left:
android:button="#null"
android:drawableRight="#android:drawable/btn_radio"
But when I do it it uses the android's ugly drawable. Is there a way I can change it to my own customized Radio Button?
Thanks in advance! :)
The default drawable btn_radio is in fact a selector.
For example, the api 15 has for that element this description :
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:state_window_focused="false"
android:drawable="#drawable/btn_radio_on" />
<item android:state_checked="false" android:state_window_focused="false"
android:drawable="#drawable/btn_radio_off" />
<item android:state_checked="true" android:state_pressed="true"
android:drawable="#drawable/btn_radio_on_pressed" />
<item android:state_checked="false" android:state_pressed="true"
android:drawable="#drawable/btn_radio_off_pressed" />
<item android:state_checked="true" android:state_focused="true"
android:drawable="#drawable/btn_radio_on_selected" />
<item android:state_checked="false" android:state_focused="true"
android:drawable="#drawable/btn_radio_off_selected" />
<item android:state_checked="false" android:drawable="#drawable/btn_radio_off" />
<item android:state_checked="true" android:drawable="#drawable/btn_radio_on" />
</selector>
So, to override that you would need a selector that follows the method but uses your own images.