Android :Button drawable Top - android

I want to create metro UI, so I did like in the picture But the problem is the position of the icons, they are in the top of the button, and I don't think it's aesthetic interface. I inserted the icons in the drawable Top in the button. Well how can make the a little bit in the middle.

You have to set the android:paddingTop and android:paddingBottom eqaully. Just don't copy and paste 10dp as the value of the padding. Value depends on the size of your button. Refer to below:
<Button
android:id="#+id/find_teacher"
style="#style/page_button"
android:drawableTop="#drawable/ic_search_light"
android:text="#string/find_teacher"
android:paddingTop="10dp"
android:paddingBottom="10dp"/>
This is the output:

I can remember 2 options:
top padding
gravity
You might wan't to check the layout documentation

Related

How to set top and bottom drawablePadding in textView

The android:drawablePadding attribute exists in the TextView class. Helps to fill space between text and drawing in TextView. But is there a way to create upper and lower padding without custom views?
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:gravity="center_vertical"
android:textSize="16sp"
andtoid:drawableEnd="#drawable/arrow"
tools:text="Text" />
No, you can only set padding on all sides for drawable in TextView.
The android:drawablePadding attribute will give you the padding between your drawable and your text, if your drawable is on top or bottom, then you can change the upper or lower padding respectively, otherwise it is not possible to set it because there is no method or attribute related, as you can see in the TextView's documentation.
If you want a workaround you can change your drawable setting blank spaces or changing it's size, but the best solution would be making a custom view or using a third party library.
Depending on the case, you can also archive the padding you want setting the padding of the TextView itself and working with the size of the text and the drawable.
Add this attribute in TextView android:drawablePadding="10dp" to set all direction equal padding. drawablePadding The padding between the drawables and the text.
Thanks everyone for answers. I achieved the result with TextView + ImageView, because there is no ways to create upper and lower padding of endDrawable in TextView.

Change Android EditText background color

I am developing an Android app. There's this issue with the EditTexts, because in some devices the "background" is white (which is the way I want it), but on others is transparent, and makes the app less professional. Here's an image with the "white background":
On other devices the edit texts that say "Yo" and "Casa" are transparent, so the words mix with the map and its pretty awful. I have tried changing the background color in the android layout xml. The closest one was I believe #drawable/white, but slightly changes the position and size of the edit text, making them look like they're one and its even worst.
Here is an example:
Is there a nice way to approach this problem? I read somewhere that an option was to add a white background image to the edit texts, but seemed like a lot of trouble.
UPDATE
I tried adding a background image, but its the same as changing the background color to any color using the android:background, the edit texts get like smaller or something. I added a blue "delimiter" to the image and this is the result:
But I want them like in the first picture, not so close one to another.
This would be the code of the edittext layout XML, the other one looks very similar. Only by adding the android:background tag changes from picture 1, to picture 3
SOLUTION
To solve this what I did was set a background image and set its height in dp as follows:
<EditText
android:id="#+id/markerTitle"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/buttonModifymarker"
android:ems="10"
android:inputType="textPersonName"
android:text="Título"
android:background="#drawable/editwhite"
>
Why don't you try setting the background of EditText programmatically?
yourEditText.setBackgroundColor(Color.WHITE);
or...
yourEditText.setBackgroundColor(Color.parseColor("#ffffff"));
simply you can add android:background="#drawable/white" attribute to your element in layout xml. you can use a lot of color resource between the double quotes (like from android color resources).
put the following image which has a solid white background in the drawable folder (it may dont appear because it's white and this page's background is white also) right click under this paragraph and select "Save Image as".
and refer to it in your layout and you will get a result like the following image
if the issue continue after trying this, please show me your layout code or email me at : mohamed_hamed4158#yahoo.com , thanks for voting my answer :)

How to use small buttons on android and still show text?

I am designing a calculator application I need some of the "less" important buttons to be smaller. I have a LinearLayout and I have set the height of the buttons to 16dp. I have also set the font to 10sp but the text will no show if I dont wrap_content.
I have also read about that padding can be a problem and I have ensured that it is equal to zero.
Is there anyway to have a small button and still show text on it?
The code for the Button:
<Button
android:id="#+id/SIN"
android:layout_width="fill_parent"
android:layout_height="16dp"
android:layout_marginBottom="#dimen/button_marg"
android:layout_marginLeft="#dimen/button_marg"
android:layout_marginRight="#dimen/button_marg"
android:layout_marginTop="#dimen/button_marg"
android:background="#drawable/keypad1"
android:minHeight="12dp"
android:minWidth="0dp"
android:onClick="onClick"
android:text="sin"
android:textSize="#dimen/spec_button_text_size" />
use android:padding="0dp" If not neccessary dont use margin
reduce the text size, and for layout_width and layout_height, wrap content should work out. And you can use layout_weight attibute for buttons. Assume you have 5 buttons, if you dont specify layout_weight for them Android will automatically divide LinearLayout to 5 pieces where each button will accommodate equally, but you can specify this attribute on your own to make buttons smaller, like if you give 0.1 on 4 buttons and 0.6 for the last button.
P.S. normally the total should equals to 1 but if you want to change it also, you can specify it in your LinearLayout attribute named layout_weightSum=""

Any way to remove the grey background from ImageButtons?

I have an ImageButton and I'd like to remove the ugly (IMHO) background that surrounds the Image. I could just add an ImageView, but they're very hard to get set perfectly in a Layout like the grey one pictured. [gravity "Center" doesn't make it go to the middle, just centers it Vertically.)
So any way to remove that?
Just use android:background="#0000"
(#0000 same with #00000000)
or
ImageButton imageButton = new ImageButton(this);
imageButton.setBackgroundDrawable(null);
The default background is not transparent.
So, just add the transparent color "#00000000" as you background, then you could solve it.
p.s. #00000000 is the transparent color
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"
android:background="#00000000"
/>
You can keep the square box and just change its color like this:
android:backgroundTint="#color/colorPrimary"
works beautifully
I'm having the same problem but now it has been solved. If you are using "android:background="#null" it will resulted of no background at all and no button pressed animation will be appeared to the user.
Just adding this line of code to make an image button become flashing upon clicked. This is the proper way to alert the user an image button has been clicked.
"android:background="?android:selectableItemBackground"
just useandroid:background="#null" in your xml
if you set the
android:background
instead of
android:src
it should overwrite the gray background
Yeah. If you drag ImageButton that will usually ask for ImageSource. But the ImageSource(android:src) doesn't remove the gray background. It is an image that should be on top of background:
Instead of that try android:background in layout XML.
please use the Draw 9-patch format for the image b'use it is provided by SDK
1. From a terminal, launch the draw9patch application from your SDK /tools directory.
2. Drag your PNG image into the Draw 9-patch window (or File > Open 9-patch... to locate the file). Your workspace will now open.
The left pane is your drawing area, in which you can edit the lines for the stretchable patches and content area. The right pane is the preview area, where you can preview your graphic when stretched.
3. Click within the 1-pixel perimeter to draw the lines that define the stretchable patches and (optional) content area. Right-click (or hold Shift and click, on Mac) to erase previously drawn lines.
4. When done, select File > Save 9-patch...
Your image will be saved with the .9.png file name.
Use like this
android:background="#android:color/transparent"
android:src="#drawable/icon"
All proposed solutions remove the ripple animation (on tap)
Settings background tint mode to 'add' will remove the background and keep ripple animation:
android:backgroundTintMode="add"
If using Xamarin Forms it can be done like this in the xaml view. Set background to transparent.
<ImageButton BackgroundColor="Transparent"

android checkbox alignment

this image show the default implementation of check box in android.
In this image check box is centre to the text. I want it to the top. what should i do?
I used Relative layout. In <TextView> i used the following code for top padding and my problem gets solved. :)
android:layout_marginTop="6dip"
Have a custom 9-patch checkbox button with the stretchable portion defined at the bottom.. so the actual checkbox will be at the top and the rest space will be filled with transparency

Categories

Resources