How to create an iOS style arrow button in Android? - android

I am partial to dual use buttons in iOS, like in the image below:
How can I create these types of buttons in Android? In other words, the entire button must be clickable, the arrow must be right-aligned and the text of the button must be left aligned.
I tried playing with a regular Button widget, but no luck. Do I have to resort to a Table layout (but then the clickability would be lost).

You will need customized shape background for the Button
You can find customizing shape here.
Set that background to the Button from xml, and for showing arrow, you will need to add arrow.png to your project drawables.
you will add attribute to button like this:
<Button android:backround="#drawable/cell_background"
android:drawableRight="#drawable/arrow" ... />

Related

how to have string and image as a content of a button

I have a button in which I set its background a to 9 patch drawable and I set the text to some value. All works well. Now I want to add an image with the text (so text and image inside the button).
How can I do that?
Thanks
You can use styles in your button layout xml.
style="#style/settingTextView"
This will turn your button to the buttons you see in the settings APP. Then you can add left and right images to your button. Using -
android:drawableRight="#drawable/some_image_right"
android:drawableLeft="#drawable/some_image_left" android:text="#string/button_text"

creating an "elevated button" effect in android

I want the button to appear as though it has space in between the bottom of it's face and the canvas. Then, when clicked, it will appear as though there is no space between the button and the canvas. I know I can style the button with xml to give it those 2 looks but I don't know how to do the elevated look.
My question is how would one go about doing this?
Easiest approach to this is creating 2 background images, each fitting the state you want, then you can either set the backgrounds according the button's state, or change the backgrounds by setting an onTouchListener to the button.

Custom picture for button in Android?

I want to implement a star as a button in Android so that when a user wants to favorite their 'current settings' they touch the star, which then turns yellow.
How would you do this? Can you change the default button? Or can you just import the picture and then set like an OnTouchListener?
If someone could also tell me how to import a picture (star), that would be beneficial as well.
Thanks for all the help.
Declare an ImageButton that has the star as it's background. Then you can register a listener for when the button is pressed to either show or remove the star.
Note: removing the star is equivalent to setting the imagebutton's background to null in most cases.
To import the star, put it in your "res/drawables" directory and then reference it in xml or in your Java code.
You can just change your button background when ever user clicks on it you just need to have two image for star one is for selected mode and another is for unselected mode.
So when ever user click you can toggle the selection and sets the desired image as background.
I suggest you to check RatingBar which is a star.
http://developer.android.com/reference/android/widget/RatingBar.html
A RatingBar is an extension of SeekBar and ProgressBar that shows a rating in stars. The user can touch/drag or use arrow keys to set the rating when using the default size RatingBar. The smaller RatingBar style ( ratingBarStyleSmall) and the larger indicator-only style (ratingBarStyleIndicator) do not support user interaction and should only be used as indicators.
When using a RatingBar that supports user interaction, placing widgets to the left or right of the RatingBar is discouraged.
The number of stars set (via setNumStars(int) or in an XML layout) will be shown when the layout width is set to wrap content (if another layout width is set, the results may be unpredictable).
The secondary progress should not be modified by the client as it is used internally as the background for a fractionally filled star.
<RatingBar
android:id="#+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:clickable="true" android:numStars="1"/>

what is use of image button?

I'm new to Android application development.
I would like to ask the use of image button in Android programming when simple button can also add the image with the button. How can we generate click event of image button?
The Image Button control is a special type of button that displays a Drawable graphic instead of text.
The Image Button and Button controls are both derived from the View class, but
they are unrelated to each other. The Button class is actually a direct subclass
of Text View (think of it as a line of text with a background graphic that looks
like a button), whereas the Image Button class is a direct subclass of Image View.
If you will look in the API for Button you will see that it has a method called setOnClickListener that is inherited from View. Since ImageButton is also a view, you can also call the same method for it.
The only way that I see to use an image in a Button is by using android:background in the XML. This is only used for setting what's shown behind the text of a button. You should use ImageButton when you want to make a button that only uses the image as its defining feature. If you end up wanting to only see the image and have no part of the button background visible, you can set android:background on the button to use an invisible Drawable.

Android: How to do create custom EditText with a clickable arrow on the right

I would like to have an EditText with one modification: on the right but still inside the EditText there should an arrow pointing downwards that I can set OnClickListener to so that when the user clicks on the arrow it displays a menu.
What is the best way to do this?
Do you mean something like this ?
see image
Add the arrow by setting the drawable right attribute
android:drawableRight="#drawable/right"
to your EditText. Then you would need to set an OnTouchListener to get the events.
I did this by putting EditText and a Button into RelativeLayout, the Button (which has custom background drawable) is overlapping the EditBox.
When user clicks on it, the EditBox doesn't receive the click event.
Sounds like a combo box. If you look at the "Building Custom Components" section of the Dev Guide, they mention combo box briefly, but give details on how to build any custom component.

Categories

Resources