The two buttons in the bottom of the screen are Scan and Leads, if we click on any button, the view of the button is visible like pressed as u see in image for lead button, this view will change according to the button click, and here i am unable to create that kind of look and feel for buttons. please provide me the sample code or suggest me to achieve this look and feel.
Thanking you
this is custom button .A custom button is very easy to create, you just have to make different images for the different state of the button and place it into your res/drawable folder.
below link contain the step by step description for creating this:
http://androidemulator.wordpress.com/2011/11/03/creating-custom-buttons-in-android-applications/
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/button_some_name_pressed" android:state_pressed="true"/>
<item android:drawable="#drawable/button_some_name_default"/>
</selector>
Have this in your /drawable/ folder as button_some_name.xml
Then have the button_some_name_pressed.png & button_some_name_pressed.png in your drawable-ldpi drawable-mdpi etc
There are other states to consider as well
ref: http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
Related
While I was creating Calculator app same as installed in my S6 edge, I stuck when
design buttons. I want to make buttons look exactly same as calc app which comes in all samsung phones.I tried state button pressed but they have design like fading colors in and out for seconds which I ain't sure how to create.
by simple way create new xml file called clickable_button.xml
inside it write this code
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/button_clicked" android:state_pressed="true"/>
<item android:drawable="#drawable/button"/>
</selector>
don't for get to make two drawable files one seem clicked and another not clicked
finally set your button background with clickable_button ;)
I'm doing a multiple choice quiz app. It has 4 radio buttons. What I want to have is have 3 icons -> No answer yet, right answer, wrong answer. So before any choice is clicked, all are non-answer, when an answer is clicked, if it is right, it light up green, if wrong - light up red. Is it possible to do with radio buttons? Or do I have to find another way out? Like using an ImageView?
Create one XML in "drawable" folder "radio.xml"
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/radio_on" android:state_checked="true"/>
<item android:drawable="#drawable/radio_off" android:state_checked="false"/>
</selector>
Take a look On this Answer.
But u want verification for selected answer. I recognized to u that..Use ImageButton with TextView in your xml file Instead Of RadioButton.Initially Set notChecked image as background of ImageButtons .when User click on Any of your ImageButton. U can verify it On its OnClick event that is it r8 answer or not and then u can set Checked image(red/green) as background image of selected ImageButton.
I want to add a border to a borderlessbutton. However, if I create my own style with the parent borderlessbutton and I overwrite the background tag I loose the state change animation etc, as this is also defined by the background. I also cannot implement them myself as the native android drawables are not available as public and therefore not accessible. I do not want to have to copy the drawables.
Is it only possible to overwrite ondraw progammatically or is there an xml based solution i am missing?
(btw this is for a periodic table so this should not involve having an xml file for each button as there are about 100 of them)
thanks
stephan
The bulk of this comes from this article.
There is a 4 step process to doing something like this:
Create an XML file that contains the states.
Create an XML file (Or background) for each state
Create the style of the button
Add the button to your layout, and see what it looks like.
The single most difficult thing is the first step, so I'll show that one here. For the other ones, you can visit the site or do your own thing. Essentially, it will look something like this. Basically needs to capture all of the 4 states. This should be saved in the drawable folder, and the name of this is what your application will use for the name of the drawable.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_enabled="false"
android:drawable="#drawable/loc_for_button_disabled" />
<item
android:state_pressed="true"
android:state_enabled="true"
android:drawable="#drawable/loc_for_button_pressed" />
<item
android:state_focused="true"
android:state_enabled="true"
android:drawable="#drawable/loc_for_button_focused" />
<item
android:state_enabled="true"
android:drawable="#drawable/loc_for_button_enabled" />
</selector>
An easy way would be to place your button within a separate layout, e.g. a LinearLayout and give this layout a background color and a padding of e.g. 1dp. This would render a "border" around the button. Note, that this is quite costly in regard of layouting, so do not use this method when you have lots of buttons.
The correct solution would be to create your one drawables for all states and build a statelist drawable with your drawables and assign this statelist drawable as your button's background. Actually it's not that much work, just have a look at http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
In my android application i want to create three different image of a single image for each state pressed , default and focussed. Is there any tool that can help me to create these images.
I think you misunderstood my problem, i knows that how to use three different image for three different states. I only wants to know that how two create those three images.
here http://code.google.com/p/iosched/source/browse/android/#android%2Fres%2Fdrawable-hdpi
you can see that there are three different images for three differenct states
home_btn_announcements_default.png
home_btn_announcements_pressed.png
home_btn_announcements_selected.png
I wants to know that is there any tool that can create the above three images. I think now my question is clear to everyone.
My Question was that how to add white border for default image , gray border for focussed image. I know that how to change image according to different states. I want to ask you that is there any tool that can put white or gray border around my image.
Use selector save this file in drawable/click.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="false" android:drawable="#drawable/notPressedImage ></item>
<item android:state_pressed="true" android:drawable="#drawable/PressedImage" ></item>
</selector>
use click.xml (click) as button src...
I want to create a 2-state-switch button (on/off) like in doubletwist alarm clock
-> http://www.design-by-izo.com/wp-content/uploads/2012/03/Screenshot_2012-03-30-20-11-30.png
When pressing the button it switches its caption with a fancy slide-in effect.
I already know about android animations, but anyhow I dont get this work within a single view.
EDIT: is there any way to do this, prior to ICS? (without taking ICS' code...)
Any Idea?
You're looking for an android switch - It's already been done for you. You just need to supply your own custom images for the switch's style
There is no slide effect on Android like on iPhone. However doing a two-state btn is easy. Just create an xml file like this and put the drawables in the folder:
<?xml version="1.0" encoding="utf-8"?>
<item android:drawable="#drawable/my_btn_pressed_bkgnd" android:state_pressed="true"/>
<item android:drawable="#drawable/my_btn_disabled_bkgnd" android:state_enabled="false"/>
<item android:drawable="#drawable/my_btn_unpressed_bkgnd" android:state_enabled="true"/>