How to make a non-holo button with DialogFragment - android

I am building an application to show a dynamic picture and a dialog with a button. The thumbnail of that picture is then used as the background of the button. However, if the picture is with black pattern, it turns out showing as "holo" and transparent to the background. This makes the button ugly.
I am trying this on android 4.x.
I have tried using different themes for the dialog, Theme.Dialog, Theme.Holo and Theme.Light but no luck.
My problems are
(1) how to make a non-holo button with DiaglogFragment(even on a holo theme view/activity).
(2) is this related to android versions? or machines?
Thank you.

you need to create a selector with all the different states of a button and for each state you will need an image
for example
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/blue_curve" android:state_enabled="true" android:state_pressed="false"/>
<item android:drawable="#drawable/blue_curve_pressed" android:state_pressed="true"/>
</selector>
then set the background to the selector in your xml

Related

Why does a Button loses its original behaviour after changing its color?

I am writing an Android app and now I am styling it. I am using a custom theme which is a child of Theme.Holo.Light. I really like Theme.Holo.Light because its buttons have a special effect when you click and hold it. Like the lower button in the picture below:
Not click:
click:
The upper button has been changed color. Now when I click on that button, it doesn't have that effect. I really don't understand why. Can anyone tell me why this happens and how can I get the same effect with a colored button?
And also, the colored button seems fatter.
This is because the button uses a selector to display different colors/effects/drawables based on the state of the click. You can check out the link on Color State List Resource.
To create your own you have to create a slecetor cml file and put it in your drawables folder.
For example.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/shape_btn_default_normal_gray" android:state_enabled="true" android:state_pressed="false"/>
<item android:drawable="#drawable/shape_btn_default_pressed_gray" android:state_pressed="true"/>
<item android:drawable="#drawable/shape_btn_default_disabled_gray"/>
</selector>
or with colors
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/dark_green" android:state_enabled="true" android:state_pressed="false"/>
<item android:drawable="#color/light_green" android:state_pressed="true"/>
<item android:drawable="#color/gray"/>
</selector>
To apply this you have to set the background drawable in your layout xml like this.
<Button
android:id="#+id/my_btn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Some text"
android:background="#drawable/selector_btn_default_gray"/>
That is the "ripple effect" of material design.You have define you own style for that effect.Link below may help you or you may search for many other answers on StackOverflow. Material effect on button with background color
It does not loses its behavior you can see after click (in your second image) the button show same scale as the above have...so by default the background is set as to show that it is button (like with padding or so) and can changes to show oncklick effect...
So when you set your desire background to button...It takes complete change on what is on presently on it and then you have to manually set onclick effect..

Custom Holo Button

I've tried searching and using custom selectors other people have posted here, using the set colour filter and various other things. I think I'm getting it completely wrong because in complete honesty I'm not great with designing having just started developing, but I still don't imagine it can be as complex to do what I want as I have seen:
I've developed an app for froyo and up. I want the background colour of the button to be the holo green and holo orange as on the swatches on the Android developer website. That's all I want to be different. I want the standard blue highlight when pressing the button on holo or the standard button onpress etc. behaviour expected in froyo, gingerbread etc.
I would really appreciate any guidance on this. Thank you guys in advance!
EDIT :
There is a much easier way to change the colors of the holo theme. This website will do it for you :
http://android-holo-colors.com
The only way to customize the holo buttons is to edit the button drawables with an image editor like Photoshop. Here is how :
Open the platforms/android-17/data/res folder in your SDK directory and find the holo buttons in the drawable folders (they start with btn_default_holo_...).
Open them with your image editor and simply change their colors (hue/saturation) to match the color you want. There are 3 or 4 different drawables, one per button state.
Save them in the corresponding drawable folder of your app. You have to do this for each screen density you want to handle (mdpi, hdpi, xhdpi are usually enough).
I haven't tested, but it may be enough to just edit the xhdpi buttons. They will be scaled down to the lower densities.
Once you customized each drawable, you have to create a selector that you will use as your custom button. Here is an example of a selector I use in one of my apps to create a green holo button :
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="#drawable/__btn_green_normal_holo_light"/>
<item android:state_window_focused="false" android:state_enabled="false"
android:drawable="#drawable/__btn_default_disabled_holo_light"/>
<item android:state_pressed="true"
android:drawable="#drawable/__btn_default_pressed_holo_light"/>
<item android:state_focused="true" android:state_enabled="true"
android:drawable="#drawable/__btn_default_focused_holo_light"/>
<item android:state_enabled="true"
android:drawable="#drawable/__btn_green_normal_holo_light"/>
<item android:state_focused="true"
android:drawable="#drawable/__btn_default_disabled_focused_holo_light"/>
<item
android:drawable="#drawable/__btn_default_disabled_holo_light"/>
</selector>
Here is an example of a modified green holo button drawable. You can check the other drawables of my project if you are interested, I do exactly what you want to do (I also have a red button).

Android ActionBar styling issues

I want to have custom background for the menu items displayed in the ActionBar. I found out that I can do that by adding the following item to my app theme style definition:
<item name="android:actionBarItemBackground">#drawable/actionbar_button</item>
Where actionbar_button.xml contains:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/action_btn_on" android:state_pressed="true" />
<item android:drawable="#drawable/action_btn_off" />
</selector>
However, this causes the background image to also render behind the custom app logo displayed on the left of the ActionBar. After several attempts at figuring out a selector that would include only the buttons, I came up with this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/action_btn_on" android:state_pressed="true" android:state_enabled="true" />
<item android:drawable="#drawable/action_btn_off" android:state_pressed="false" android:state_enabled="true"/>
<item android:drawable="#android:color/transparent"/>
</selector>
Which sort of worked, and after the app loads fully the background behind the logo is transparent as I want it. But the problem is that while it's still loading it briefly shows the logo with the button background behind it and more annoyingly, it scales and crops the logo to fit inside the fill area of the 9-patch graphic that is the button background. When finished loading, the background is switched out, but the scaling and cropping remains, which looks quite ugly. How can I fix it?
Have not found a working solution to the general problem of setting image-based backgrounds to ActionBar buttons, but the scaling/cropping does not happen if I use entered XML based backgrounds, such as created with a layer-list of shapes. For some cases in may not be viable, but in my case it was entirely possible, and maybe even better than using a bitmap based resource.

ImageButton effect on Android 3.0+

I want to have an onTouch effect like the Home Button on Android 3.0+.
Is there a property to do so easily?
Or I have to do it all myself? And how?
Thanks!
UPDATE:
Here is the screenshot: http://i.imgur.com/1eyVE.jpg
I would like to have the same blue, circle, fade-out effect.
What you're talking about is called the Navigation Bar. The animation and circle effect used when you touch a button are from a custom class that's extending ImageView.
You can view the full source for that class here.
As far as the Holo blue color goes, you can visit the Android Design Guidelines - Color section to look at all of the colors used in Ice Cream Sandwich. Move your mouse over a specific color in the palette to learn the corresponding hex value.
I'll leave this example here in case you decide not to use the KeyButtonView class.
Holo selector example:
<?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:drawable="#color/holo_blue_dark" android:state_pressed="true"/>
<item android:drawable="#color/holo_blue_dark" android:state_enabled="true" android:state_focused="true"/>
<item android:drawable="#color/transparent"/>
</selector>

How to apply shadow color to Android EditText when focused?

I have an EditText control in my application and when it is focused (i.e. I'm ready to enter something) I want to apply shadow color to it. How can I do this?
Thanks,
#nagaraju.
You can use the Selector tag like Follows:
Create a New xml file and place it in your drawable folder and name it as shadow_color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="false" android:drawable="#drawable/ask_footer"/>
<item android:state_focused="false" android:state_pressed="true" android:drawable="#drawable/askfooter_hover" />
<item android:drawable="#drawable/ask_footer" />
</selector>
And then go to that xml in which your EditText is declared:
And write one attribute in editText
android:background="#drawable/shadow_color"
and you are done.
Use a selector for your background drawable and create your own nine patches.
does shadow color mean you want a shadow theme background for your view??
then, assuming that you are using xml layout,the GU interface version shown on eclipse allows you to select a particular theme for your view,which i think is what you want.
if you want to put it manually,
you must mention it in the android manifest
eg.
<activity android:name=".activity_name here"android:theme="#android:style/Theme.Dialog">//there are a handful of effects provided by SDK
</activity>
i suggest the graphical user interface method,its easy and you can see the effect as you select the theme
You can also check whether your EditText isFoucsed or not. And if true so change its background image to shadow like image.

Categories

Resources