My button looks like this"
How can i make a simple button same as this
and this is sample of my xml code:
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="MatchCenter"
android:elevation="10dp"
android:paddingBottom="5dp"
android:layout_margin="10dp"
android:drawableTop="#drawable/football"
android:singleLine="true"
android:background="#drawable/my_button"
android:id="#+id/MatchCenter"
android:textAllCaps="false"
/>
Try using a 9-patch as your background https://developer.android.com/studio/write/draw9patch.html
Related
I am creating a calc app.
How to set padding to shrink the background image..
I want to convert to something like
My xml of TextView :
<TextView
android:id="#+id/c_tv_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:gravity="center"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:text=""
android:background="#drawable/ic_backspace_black_24dp"
android:padding="5dp"/>
Use ImageView instead and give padding to it :
<ImageView
android:padding="20dp"
android:src="#drawable/ic_backspace_black_24dp"
android:id="#+id/product_main_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
and why you need Textview and Background image to that ?
You can simply put ImageView or ImageButton
You should use imageButton instead of TextView like this:
<ImageButton
android:id="#+id/delete_button"
android:layout_width="70dp"
android:layout_height="40dp"
android:background="#drawable/delete_icon"
android:layout_margin="16"/>
I suppose there's more than one way
First way, you have to extends TextView into new class and overwrite some #override methods. and use this class in xml... this is hard way
Second way (Recommended), use Adobe Illustrator or Photoshop to adjust a new drawable and make it easily as you like
Third way, use RelativeLayout or FrameLayout and make the background you want in a Imageview... easy way and do the job
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:id="#+id/iv1"
android:padding="your_padding_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_backspace_black_24dp"/>
<TextView
android:id="#+id/c_tv_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dp"
android:text=""
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_alignBottom="#+id/iv1"
android:layout_alignEnd="#+id/iv1"
android:layout_alignStart="#+id/iv1"
android:layout_alignTop="#+id/iv1"/>
</RelativeLayout>
How can I place drawableLeft and button text of AppCompatButton like in the image below?
I have tried to apply paddingLeft, but the text is moving away from the drawable to the right.
<android.support.v7.widget.AppCompatButton
android:id="#+id/filterBy"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="#drawable/ic_btn_filter"
android:paddingLeft="20dp"
android:text="#string/filter_by"
android:textAllCaps="false" />
And so far the result is looking like
Layout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/profileHeader"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp">
<android.support.v7.widget.AppCompatButton
android:id="#+id/findFriends"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="#drawable/ic_btn_search"
android:text="#string/find_friends"
android:textAllCaps="false" />
<android.support.v7.widget.AppCompatButton
android:id="#+id/filterBy"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="#drawable/ic_btn_filter"
android:text="#string/filter_by"
android:textAllCaps="false" />
</LinearLayout>
And the interpreted requirement for making things clear.
Using layout_weight property am adjusting the width of both buttons and what i have to do is, the text should be in center of the button
and the drawable should be aligned near left of the text.
Any suggestion please?
use
android:drawablePadding=""
probably you can't, if you want like this then you have to make it using complex layout like this see
each time I add and image to my button (want to add it below the text) it only shows the top left of the image and adds itself at the top of the button even when I use android:drawableBottom .
here is my XML code :
<Button
android:layout_width="162dp"
android:layout_height="200dp"
android:text="#string/weather_station"
android:textStyle="bold"
android:textSize="18dp"
android:background="#drawable/weather"
android:paddingBottom="120dp"
android:paddingLeft="5dp"
android:typeface="monospace"
android:id="#+id/weather_station" />
android:drawableBottom="#drawable/weatherman"
/>
use ImageButton instead of using Button and try to scale the image`
<ImageButton
android:id="#+id/my_image_button"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:src="#drawable/my_img" />
<Button
android:layout_width="162dp"
android:layout_height="200dp"
android:text="bUTTON"
android:textStyle="bold"
android:textSize="18dp"
android:background="#drawable/shape1"
android:paddingBottom="120dp"
android:paddingLeft="5dp"
android:drawableBottom="#drawable/cast_ic_notification_2"
android:typeface="monospace"
android:id="#+id/weather_station" />
how cant it possible even your drawable line out of scop ? try above WORKING CODE
Try setting up the below scale type in the xml for fill image in button.
android:scaleType="scaleXY"
So put this attribute in your xml code.
<Button
android:layout_width="162dp"
android:layout_height="200dp"
android:text="#string/weather_station"
android:textStyle="bold"
android:textSize="18dp"
android:background="#drawable/weather"
android:paddingBottom="120dp"
android:scaleType="scaleXY"
android:paddingLeft="5dp"
android:typeface="monospace"
android:id="#+id/weather_station"
android:drawableBottom="#drawable/weatherman"/>
I am trying to create a Button that looks like a Spinner.
I have done this by creating a Button like this:
<Button
android:id="#+id/dateButton"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/dateLabel"
android:text="default text"
android:textSize="15sp"
style="?android:attr/spinnerStyle"
android:gravity="center_vertical|center_horizontal" />
The problem is that the text ("default text") inside the Button seems to have extra padding around it, which makes the Button look bloated and expanded in its height.
I thought that setting the layout_height for the button to "wrap_content" would fix this and make the button thinner, but it does not have any effect.
Does anyone know how to make this button's height wrap to the text inside it?
Here is the example code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="10dp" >
<TextView
android:id="#+id/dateLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:text="Select date:"
android:textSize="15sp" />
<Button
android:id="#+id/dateButton"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/dateLabel"
android:text="default text"
android:textSize="15sp"
style="?android:attr/spinnerStyle"
android:gravity="center_vertical|center_horizontal" />
</RelativeLayout>
android:gravity="center_vertical|center_horizontal" instead of this you can write
android:gravity="center" but as per your requirment just remove this line.do not add any gravity and change your height size android:layout_height="40dp"
i changed your code
<Button
android:id="#+id/dateButton"
android:layout_width="150dp"
android:layout_height="35dp"
android:layout_toRightOf="#+id/dateLabel"
android:text="default text"
style="?android:attr/spinnerStyle"
/>
The padding of this button is decided by the drawable of it. You either need to change the spinner drawable (can be done at runtime) , or provide your own drawable to the given button that would make it look like a spinner, without using the default one
How do I align text and image with same button? I want to do like this image:
but my button looks like this, with text overlapping the image:
This is my code below. How do I make space in between text and image in the same button?
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_weight="0"
android:weightSum="1"
android:orientation="horizontal" >
<Button android:id="#+id/btnUtilitybillpayments"
style="?android:attr/buttonStyleSmall"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:drawableLeft="#drawable/handshake"
android:layout_marginRight="55dip"
android:layout_marginLeft="55dip"
android:drawablePadding="-25dp"
android:paddingLeft="10dip"
android:paddingRight="50dip"
android:layout_marginTop="10dip"
android:background="#drawable/curvedplanebutton"
android:textColor="#drawable/button_text_color"
android:text="Utility Bills Payment"/>
</LinearLayout>
try this
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#android:drawable/btn_star_big_on"
android:text="Drawable left">
Button>
For more info go to this link
http://izvornikod.com/Blog/tabid/82/EntryId/8/Creating-Android-button-with-image-and-text-using-relative-layout.aspx
I think you made your button to Complex,
Just use below code and let me know what happen..
<Button android:id="#+id/btnUtilitybillpayments"
style="?android:attr/buttonStyleSmall"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginRight="55dip"
android:layout_marginLeft="55dip"
android:drawableLeft="#drawable/handshake"
android:layout_marginTop="10dip"
android:gravity="left"
android:paddingLeft="20dip"
android:background="#drawable/curvedplanebutton"
android:textColor="#drawable/button_text_color"
android:text="Utility Bills Payment"/>
As I have also doubt on layout_margin attributes of your Button. If it doesn't work then try to remove
android:layout_marginRight="55dip"
android:layout_marginLeft="55dip"
Some thing like this.
<Button
android:id="#+id/btnUtilitybillpayments"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/curvedplanebutton"
android:drawableLeft="#drawable/handshake"
android:gravity="left|center"
android:text="Utility Bills Payment"
android:textColor="#drawable/button_text_color" />
A more suitable approach is by making the button as a 9patch image. That way, you can define where the text should be by patching the right and bottom side. And there wont be any need for such complex button.
You can go here for more information-
http://developer.android.com/tools/help/draw9patch.html