How to layout a button - android

I would like to apply both an icon and text to a button. The button would have the icon centered in the button and text written at the bottom, centered. I could not get the text to center and be at the bottom using android:gravity.
A side note, for a layout with 6 buttons is a Table Layout the best way to do it? There is 3 rows and 2 columns. Thanks in advance.
Another side note, why does the button lose its rounded edges when I add background color?

You can use android:drawableTop attribute to set drawable on the top and text on the bottom.
You should also use stateful drawables.

Related

How to change the gap between icon and text?

Picture
To see the picture , please click the link at the top.
Here is a ViewPager + TabLayout。
I use the following code to create the tablayout.
firstTab.setIcon(R.drawable.tab_home_green).setText("HOME");
secondTab.setIcon(R.drawable.tab_explore_grey).setText("EXPLORE");
thirdTab.setIcon(R.drawable.tab_me_grey).setText("MIME");
Now the gap between icon and title is fixed, In the source the gap is private. I want to know how to change the gap value?
How to change the padding of each Tab?
Create and inflate a custom tab's layout.
You can also use view tag in xml for the space between the icon

How to implement the following effects?The text color and the icon were changed after they were pressed

Here's the pics,the icon and the text color,and the background color changed .
When right layout is pressed
you can use selector for the background.
For the location you can use LinearLayout with horizontal orientation, and set weight for childs.
http://www.compiletimeerror.com/2014/03/android-button-selector-tutorial-with.html#.Vt6dQuZRLuw
Here is an example how to reach it.
Good luck!

Android Custom Image Buttons

I'm new to Android development and I'm trying to implement some custom buttons, they should look something like this:
So I was wondering if I can use something like a imagebutton and use the image as a background and add text on top of it (I tried this but the text is always in the middle and doesn't have a label so its hard to see..), or should I write a custom style or theme for my button. In case that I have to write a custom style or theme, could you please help me out with this? How should I go about doing it?
For each of those Grid elements, create a framelayout for each, put the background and then the label in front. Frame layouts allow things on top of each other. You can put the labels with layout_gravity bottom and also add a transparent color to it so the image in the back can be seen. Also add a onClickListener to each of the framelayouts so they act as buttons.

How to create arrow type layout?

I have start and end date time fields that look like in picture below. Blue color shows active selection - if we select right then blue color goes to right and white color appears on the left and vice versa.
Hardest part is to create that arrow style in the middle. What should i use because buttons are rectangles and I don't know how it could be done.
It's easy. Just use ninepatch.
You can start there:
http://radleymarx.com/blog/simple-guide-to-9-patch/
you need a custom image according to what you ask, maybe extend ToggleButton for that but basically what you want is the same component when pressing on two different places on the same component will dispatch different events.
I would for example extend Linear layout, make it vertical layout, put two clickable textView\buttons with 9 patch images as background ,like suggested before, one for the white part and the other for the blue part. and replace the background image for any event u like.
you can also create a StateListDrawable with actions for selected and deselected and set the state of each drawable upon the right click

Android: How to put text underneath a Button?

I have...
PNG file for Background
PNG file for Icon (drawableTop)
Text I want to put underneath this Button
It's similar to a Menu Icon. How to do that? I only found following ways. Both of them arent very nice:
Make two Buttons, one for Text one for the Picture
The Background PNG File needs a transparent area at the bottom in the size of the text.
After some months of working with Android it's not that hard anymore. You can set any View (ImageView, TextView, LinearLayout, RelativeLayout...) clickable.
So in this case I would go with a Relative- or LinearLayout. They also can use the same style, so the position of the icons are always the same.
Set the text as the button text via the attribute android:text. Use the android:drawableTop attribute to set an icon that will appear above the text.

Categories

Resources