I've placed three buttons side by side using constraints, with 4dp gap between each as shown below, but due to this "extra space"(shown below), the actual gap between buttons looks greater than it is:
What is the attribute that android uses to maintain this space? How can I remove it. I'm using the default <Button> widget that is android's default button widget.
Add this attribute to the buttonstyle="#style/Widget.AppCompat.Button.Borderless". This will make your button white and borderless. After add background to your button using this. android:background="#android:color/darker_gray"
Your button should be as below.
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
style="#style/Widget.AppCompat.Button.Borderless"
android:background="#android:color/darker_gray"/>
Add Background to your Button and this space will cover by the background color.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:background="#color/colorPrimary"
android:padding="2dp"
android:layout_margin="4dp"/>
You can also use translationX and translationY property.
Related
I want to create a label like this:
Requirements are:
The rectangle should grow with the text
the length of the red line is dependent of a property
What I tried was to create a 9ng image for the background of the text and use the padding property for the length of the red line. The red line is drawn by overriding the onDraw method.
The result is that the red line is correct but the background is expanded including the padding like this:
What's the best way to do this? Building a custom view with a label included? a custom view drawn 100% programmatically (in this case, what's the method to resize a 9ng image?)?
Thanks
Julien
try this one
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="The text"
android:textColor="#000000"
android:background="#drawable/<your_drawable>"
android:textSize="16sp" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:background="#f00"
android:layout_weight="1" />
</LinearLayout>
Hope it will help you
Best way to do this is probably using two different controllers.
You set a simple textView with your rectangle as background and with the width set to wrap-content.
After this you create the line positioning her where you want (to the right of the controller or to the end of the page or where you please) and you resize it as you want.
For any doubt I'm here
http://i.imgur.com/WCGjcOe.png
Pretty straight up question - How do I remove those grey borders?
The pictures (.png files) are just the stars, text and the white around it. Then when I add them as imagebuttons they add this ugly grey borders that I really don't want.
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/starButton1"
android:src="#drawable/star_pink_1"
android:onClick="starButton1Clicked"
android:layout_below="#+id/imageView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
You have to define the xml attribute background to Your ImageButton:
android:background="#android:color/transparent"
what You see is the original button, Your src is just overlayed.
try this
android:background="#null"
this will make your imagebutton with no background.
Both codes work fine for your query :
android:background="#null"
OR
android:background="#android:color/transparent"
Use this
style="?android:attr/borderlessButtonStyle"
I created a personal keyboard and set the background image to the one of the buttons, but after that button size (with my background) is different from one another.
<Button
android:id="#+id/buttonShift"
android:paddingTop="0dip"
android:textSize="22sp"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:textStyle="bold" />
Set background:
<Button
android:id="#+id/buttonShift"
android:background="#drawable/sym_keyboard_shift_off"
android:paddingTop="0dip"
android:textSize="22sp"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:textStyle="bold" />
Please, see the screen of the buttons
Before:
After:
Image size: 106x68
I would advise you to:
Change your drawable a bit - remove the orange rectangle background, keep only the arrow with transparent background (from now on I will use the name shift_off_arrow as a name of described drawable). The transparent background should be only as big as it is needed to keep the whole arrow. Not bigger.
Define a new color - the color of your orange background (from this moment I will assume you have defined it and I will be using name orange_background)
Use ImageButton instead of Button (just like satnam singh and Hamid Shatu said in a comments to your question)
Use code like this (manipulate with all paddings to get the size of the arrow exactly like you want):
<ImageButton
android:id="#+id/buttonShift"
android:background="#color/orange_background"
android:src="#drawable/shift_off_arrow"
android:paddingTop="0dip"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1" />
How can i do 1 button with 2 labels with different style inside in android?
(Like the image)
Thank's
You can create a custom view. I have used Layout as a button by setting custom button style to the layout and have added two textViews to it, this way:
<LinearLayout android:id="#+id/customButtonLayout"
android:layout_height="wrap_content" style="#android:style/Widget.Button"
android:layout_width="wrap_content">
<TextView android:text="First" android:id="#+id/firstTextView"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textColor="#000"></TextView>
<TextView android:textColor="#000" android:text="Second"
android:layout_height="wrap_content" android:id="#+id/secondTextView"
android:layout_width="wrap_content" android:layout_marginLeft="10dp"></TextView>
</LinearLayout>
The only way I can think with which you could applay different textstyles to a Button is to use HTML (with HTML.fromHTML()). But I wouldn't recommend that, because probably it wouldn't look good. Use a Layout instead(Linear - or RealtivLayout). Add two TextViews to it and set a selector as the background(to have a "click-effect").
I am creating a custom button. I want to set the position of text on button.
I have two background images for button (button_off and button_on) first is for normal button and second is for onFocus / onPressed state.
Now I have to put text on button then it should look like:
But i am unable to set the exact position of the text on this background button image.
Please share your suggestion to solve this issue.
You can try using 9-patch image as a background. More information on this here: http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
You can set these properties in XML file, `
<Button
android:id="#+id/button1"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:drawablePadding="5dp"
android:drawableLeft="#android:drawable/ic_lock_lock"
android:text="All"
android:gravity="center"/>
`
Align the text , use gravity option ! or try with padding
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#android:drawable/arrow_down_float"
android:background="#drawable/btn_all_bg"
android:text="All">
Button>
You can use the drawableLeft/right/top/bottom to add icon on a button and text would automatically adjust.
Few ways :
define a button and try android:drawableStart
extend Button and draw yourself
try to define a LinearLayout that hold a text and an image with a
background of your button,
set both of them weight of 1 and put them inside another LinearLayout and make them onClick
can't assure 3 will work without a tweak or two but it worth trying
You can use the layout as a button style="#android:style/Widget.Button", and configure it as you want.
Paste this in your xml file:
<LinearLayout
android:id="#+id/button"
style="#android:style/Widget.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:text="TextView" />
</LinearLayout>