I am using an astuetz sliding tab strip in my android application, and I cannot seem to figure out how to get rid of the blue highlight that appears when you are selecting a tab. I have provided a picture below to illustrate the problem. Any suggestions would be greatly appreciated!
That library uses this drawable as a background:
<selector xmlns:android="http://schemas.android.com/apk/res/android" android:exitFadeDuration="#android:integer/config_shortAnimTime">
<item android:state_pressed="true" android:drawable="#color/background_tab_pressed" />
<item android:state_focused="true" android:drawable="#color/background_tab_pressed"/>
<item android:drawable="#android:color/transparent"/>
</selector>
where the color is:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="background_tab_pressed">#6633B5E5</color>
</resources>
So you can create your own selector with your favorite color.
Related
Styles.xml:
<style name="windowTitleBackgroundStyle">
<item name="android:background">#A4D05F</item>
</style>
<style name="windowTitleStyle">
<item name="android:drawableLeft">#drawable/smartlogo</item>
<item name="android:textColor">#C6C09C</item>
<item name="android:padding">12dip</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">16sp</item>
</style>
I am customizing my titlebar in android using eclipse ide. I can also see my image that is being set by the drawableleft, however it is too big. Do you know how to set the width and size of the drawableleft?
you can use a xml-drawable, that you can customise as you wish.
You can find here some examples and a lot others on net.
Alternatively, you can also create a simple XML, containing a view, image etc, like this:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="#drawable/icon"
android:width="#dimen/icon_size"
android:height="#dimen/icon_size"
/>
</layer-list >
,and use this as your drawableLeft.
Hope this helps!
if API level 23 and higher you can change like this
<item
name="android:drawableLeft"
android:drawable="#drawable/smartlogo"
android:height="24dp"
android:width="24dp"/>
I'm trying to change the color of my switch in Android. I realize that I will need new 9patches. I went over to http://android-holo-colors.com/ and selected my color and selected (Switch Jelly Bean). To use Switch Jelly Bean I had to use: https://github.com/BoD/android-switch-backport. To import it into my project I had to add:
<item name="switchStyle">#style/Widget.Holo.CompoundButton.Switch</item>
to my styles, and then in xml I have to use the switch like so:
<org.jraf.android.backport.switchwidget.Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Now everything with the switch works fine. Next, I took everything that was output from the android holo color generator and put it into the proper files:
drawable (2 selector files)
drawable-hdpi (9patch files)
drawable-xhdpi (9patch files)
drawable-xxhdpi (9patch files)
then I added to my xml:
<org.jraf.android.backport.switchwidget.Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:thumb="#drawable/apptheme_switch_inner_holo_light"
android:track="#drawable/apptheme_switch_track_holo_light" />
but it is still the original blue color. I believe I'm doing everything correctly. Everything compiles (xml, java). Note: I AM importing org.jraf.android.backport.switchwidget.Switch in my java also. Any ideas?
As per this, (direct answer by BoD copy-paste):
You must not use android:thumb and android:track, but instead, app:thumb and app:track And you must add the following to the root of your xml document:
xmlns:app="http://schemas.android.com/apk/res-auto"
Easiest way in Android Lollipop and above,
<style name="AppTheme" parent="MaterialTheme.Light">
...
<item name="android:colorControlActivated">#color/color_switch</item>
</style>
for androidx.swithcomapact use
app:thumbTint="#color/purple_700"
app:trackTint="#color/purple_700"
Try this:
switch_thumb.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="#drawable/switch_thumb_holo_light" />
<item android:state_pressed="true" android:drawable="#drawable/switch_thumb_activated_holo_light" />
<item android:state_checked="true" android:drawable="#drawable/switch_thumb_activated_holo_light" />
<item android:drawable="#drawable/switch_thumb_holo_light" />
</selector>
In the layout of the switch:
android:thumb="#drawable/switch_thumb"
to change the color of switch you can use two images
green - when switch is ON
red - when switch is OFF
now put this file in drawable folder
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/blue_checked" android:state_checked="true"/>
<item android:drawable="#drawable/blue_unchecked" android:state_checked="false"/>
</selector>
and in the layout XML file use it as below
<CheckBox
android:id="#+id/user_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#drawable/notif_checkbox_selector"
/>
It might be that you need to put
style="#style/switchStyle"
in your XML as well
I'm using QuickAction3D library and I would like to make the background sort of opaque when the QuickAction it's clicked, just like a normal AlertDialog would do, it's there a way of doing this?.
Thank you very much
EDIT
I meant the Activity go to an opaque color, and the quick action preserve it's current color. For example, If an AlertDialog it's shown, the background activity would be turned opaque, and the AlertDialog it's on a clear color.
Quich action 3d
See in that library for the background they have used a selector drawable action_item_btn.xml, you can customize the code to make as per ur need.They have set as
<item
android:state_pressed="true"
android:drawable="#drawable/action_item_selected"/>
for the background if u want to set the selector for the items in the list u can set selector for the imageView present there like,
Create a background drawable resource, e.g. item_background.xml, in your /drawable folder, containing something like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/color1" android:state_pressed="true"/>
<item android:drawable="#color/color2" android:state_selected="true"/>
<item android:drawable="#color/color3" android:state_activated="true"/>
<item android:drawable="#color/color4"/>
</selector>
Then provide the color values in your /values/colors.xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="color1">#DDff8800</color>
<color name="color2">...</color>
<!-- more colors... -->
</resources>
Finally, set that drawable resource as the item background in your layout with android:background="#drawable/item_background".
I'd like to change the background for an image button. Basically the image I have looks great on a transparent background and a bit lousy when there are a bunch of them all with a non-transparent background.
This should be easy - just change the android:background on the button to a transparent color (via a drawable):
click_background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"><color android:color="#FF008080" />
</item>
<item android:state_pressed="true"><color android:color="#FF008080" />
</item>
<item><color android:color="#00000000" />
</item>
</selector>
Then the button
<ImageButton
android:id="#+id/players"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:background="#drawable/click_background"
android:contentDescription="#string/players"
android:src="#drawable/speaker_tile" />
The problem is that I actually want to retain the state_focussed and state_pressed versions of the background (which I presume is derived from the theme). I would like to have the background appear when the button is pressed or selected (and appear with the exact same colour/drawable) that would be used by the theme normally when a button is pressed would be helpful.
I was wondering if there is a way to do one of the following, but have so far been unable to find anything on either:
Define a selector that in some what inherits from another (similar to the way a theme can inherit from another).
Create an entirely new selector but have it's XML reference the color/drawable of the theme's state_focussed and state_pressed used for an image button. Edit: It looks like this option is out. I would have needed attributes, but you can't reference them from a drawable. See here
I'd like to do this in Declarative XML rather than Programmatic Java if possible.
You can copy the drawables used by the Android OS into your project and use them in your state-list drawable. You can find the images in {android-sdk-directory}/platforms/android-##/data/res/drawable[-*dpi]
EDIT:
If you go to {android-sdk-directory}/platforms/android-##/data/res/values, you'll find the themes.xml and styles.xml files used by Android. Using them you can figure out which drawables you'll be looking for.
For example, the default theme on newer versions of Android is Theme.Holo. This theme has a default style for ImageButtons declared like so:
<item name="imageButtonStyle">#android:style/Widget.Holo.ImageButton</item>
In styles.xml, this style is defined as follows:
<style name="Widget.Holo.ImageButton" parent="Widget.ImageButton">
<item name="android:background">#android:drawable/btn_default_holo_dark</item>
</style>
Thankfully the background attribute is right there defined in plain sight. Sometimes it's inherited from a parent style and you have to find that instead. In any case, here's the drawable (found in the /drawable directory since it's xml):
<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_disabled_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_focused_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_disabled_focused_holo_dark" />
<item
android:drawable="#drawable/btn_default_disabled_holo_dark" />
</selector>
So those are the drawables Android uses for the background of a standard ImageButton in the default (holo dark) theme.
I have the following preference screen in my app
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<EditTextPreference
android:key="edittexvalue"
android:id="#+id/edittextvalue"
android:title="Title Here"
android:summary="Summary Here"
android:defaultValue="Some Value"/>
<Preference
android:key="customPref"
android:title="Title Here"
android:summary="Summary Here"/>
</PreferenceScreen>
All of that works just fine however my app i have custom backgrounds and text colors/sizes but i can't figure out how to format the PreferenceScreen I assume you point this at another xml? but can't figure out the code i need and what changes should be made. The main concern is the background color the text is fine i guess but the background just doesn't match the rest of my app. So i'd like to set a custom background color lets say red for now (#ff0000)
I thank anyone that can help me with this problem
You can to apply a theme to it in your manifest, for example
<activity android:name=".Settings"
android:theme="#style/YourStyle"/>
and in your styles.xml (if you dont have one, create it in the values folder)
you can modify whatever you need
For example
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="YourStyle" parent="android:Theme.Light">
<item name="android:listViewStyle">#style/Widget.ListView</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="Widget" parent="android:Widget">
</style>
<style name="Widget.ListView">
<item name="android:background">#color/white</item>
<item name="android:divider">#color/gray_division</item>
<item name="android:dividerHeight">2dip</item>
</style>
</resources>
I hope this helps