I want to have a image button with three possible states and depending on the logic display any one single image per state.
I could use a relative layout with three image buttons and toggle the visibility around.
But is there a way to define 3 states for an image button and toggle the images on a button level?
Thanks
use drawable selector drawable
Related
I want to use the toggle button group to make it look like the picture below.
enter image description here
However, if I insert a button into the toggleButton Group, the size of the button becomes very small. Even if the absolute size is given to each layout, only the size of the toggle Button Group is enlarged and the button inside is small, so I can't see it. When you take out the button, it returns to its normal size and you can see it well, but it looks small only in the group.
Can I know the reasons about this?
I am guessing that there must be separate styles in the toggleButton Group itself for buttons. Maybe you wanna check that.
Another reason I'm thinking is that maybe you have the width of the button set with % percentage, or with vh/vw(view height/width). If so button will change its size relative to the parent element size.
I have 11 Buttons with Background Images and if i switch to the actual RadioButton the circle thing on the RadioButton would show up and make my Background drawables ugly is there a way to make buttons work like RadioButtons?
I'm assuming the image changes when you click on the button to show it is selected. In that case, in your onclicklistener for the first button, you could change the image of that button to show it is selected, and also change the images of the other buttons to the unselected image. Do the same for each button.
I am working with a relative layout in Android. I want to have a glow effect when I click on a relative layout on screen. How to archive it?
From what you have posted it seems you want your layout to have two different backgrounds depending on whether it has been clicked or not.
You achieve this by setting a selector to background
selector example
I'm trying to build an Android app where I would like to display some Buttons in various places, as in the demo image attached.
The challenge here is creating the custom buttons and arranging them.
As for the custom Buttons, I guess I could achieve that using CustomViews or a simple button with a Custom Drawable as Background.
Are these the right points to start, any other ideas?
On arranging them, I have no clue how to achieve that.
As Android_Crazy and Closeratio have already said, a RelativeLayout is the most suitable option for custom placement of buttons in general. However, for the exact placement of buttons pictured in your example, a LinearLayout would work just fine.
In a LinearLayout you may place views under or above eachother (with android:orientation = "vertical", relevant for your example) or next to each other (android:orientation = "horizontal"). You can also add margin to your views to alter the horizontal position (layout_marginLeft or layout_marginRight) or the vertical position (layout_marginTop or layout_marginBottom).
As for the buttons' appearance, I always use custom background drawables, usually with a custom xml to add a different drawable for when the button is being pressed or selected.
I want to create android buttons but the look something like the one in picture.
Normal android buttons are curved and their boarder are not joined... I want my layou
Is there a way to create a layout like this?
You can turn any ImageView into a button by setting an onClickListener on it.
Edit to better answer the question: The layout you show can be created by putting a bunch of ImageViews in a horizontal LinearLayout. The LinearLayout has a blue background. The images that provide the sources for the ImageViews have a transparent background.
Buttons are just TextViews extensions. You just have to change its background with a xml drawable which has three states