How to make an opaque Activity? - java

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".

Related

How to get rid of blue highlight with astuetz sliding tab strip?

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.

Android - Change drawable color in runtime

I''m using a drawable for the cells in my table layout in my Android application. I wanna change the cell colors on click event. Is it possible to change the color of the drawable in run time. my drawable is,
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape= "rectangle" >
<solid android:color="#FFFFFF"/>
<stroke android:width="1dp" android:color="#483D8B"/>
</shape>
And I wanna change the white color "#FFFFFF" with the click event. can java edits the color in the XML drawable file. Is it possible.
I just edited the background color and it dispersers the borders of the drawable.
String StatusColor=GetColor(Retailer_x.getStatus());
Stts.setBackgroundColor(Color.parseColor(StatusColor));
need help. Thank you!!!!
ShapeDrawable sd1 = new ShapeDrawable(new RectShape());
sd1.getPaint().setColor(CommonUtilities.color);
sd1.getPaint().setStyle(Style.STROKE);
sd1.getPaint().setStrokeWidth(CommonUtilities.stroke);
sd1.setPadding(15, 10, 15, 10);
sd1.getPaint().setPathEffect(
new CornerPathEffect(CommonUtilities.corner));
ln_back.setBackgroundDrawable(sd1);
Use selector of the Table Cell background to change state of the table cell when user click it.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- selected -->
<item android:drawable="#drawable/red_drawable" android:state_selected="true"/>
<!-- focused -->
<item android:drawable="#drawable/gray_drawable"/>
<!-- default -->
</selector>

Change only one state (the default state) of an ImageButton 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.

Change button background on touch

i want to change the green background of a button when this is touched without using OnTouchListener. i have this situation: i put some butons in a layer, then the layer in another layer, and the last layer in onother layer. when i touch the button the background is changing(i m using OnTouchListener right now) but if i drag the finger outside of the button and then get it out of the screen the background of the button remains the image from the state when it s touch(otherwise if i click the button and the the finnger off the button it is k the background is changing)
1. Prepare 3 images for button states, and put it into resource/drawable folder.
2. create a new XML file in res/drawable/ folder, in whatever name you want, in this case, we just give a name as my_button.xml. This file defined which button state is belong to which image.
Now, you can refer to this button via this Id : #drawable/my_button.
File : res/drawable/my_button.xml
create xml file using the button image like this with my_button.xml in drawable folder
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/button_pressed_yellow"
android:state_pressed="true" />
<item android:drawable="#drawable/button_focused_orange"
android:state_focused="true" />
<item android:drawable="#drawable/button_normal_green" />
</selector>
add a normal button, and attach the background image to above “my_button” via
android:background:#drawable/my_button
The selector will be as below
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#drawable/btn_pressed" /> <!-- pressed -->
<item android:state_focused="true" android:drawable="#drawable/btn_focused" /> <!-- focused -->
<item android:drawable="#drawable/btn_default" /> <!-- default -->
</selector>

Android Preference Screen Layout

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

Categories

Resources