ToggleButton has default padding around text if android:layout_width="wrap_content" is set. I wanted to remove all padding around text and I found out that it is achieved by setting android:minWidth="0dp". Now I could set padding to 10dp, but it will cut text at the end. Is there any way how to fix that?
<?xml version="1.0" encoding="utf-8"?>
<ToggleButton
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:minWidth="0dp"
android:layout_height="26dp"
android:background="#color/colorTextBlue"
android:textSize="12sp"
android:text="TextB"
android:textOff="#null"
android:textOn="#null"
android:button="#null"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:textColor="#color/toggle_color_selector" />
I will use custom drawable background for this button but here is some look of that button in preview:
Related
I am using the default radio button without any customization. I would like to add padding to the left of the button icon. I have tried padding-left, but it is only changing the space between the icon and text.
I know it can easily achieve by using the drawable left and setting the button null, but it could lose the animation and default style.
My code
<com.google.android.material.radiobutton.MaterialRadioButton
android:id="#+id/rb_bank"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg_payment_method"
android:buttonTint="#color/colorPrimaryDark"
android:padding="15dp"
android:text="#string/bank"
android:textColor="#color/textColorSecondary"
android:textSize="16sp" />
Current output
you can wrap the material button in a LinearLayout, set your background android:background="#drawable/bg_payment_method" to the LinearLayout and give
margin_left to the radioButton
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg_payment_method" >
<com.google.android.material.radiobutton.MaterialRadioButton
android:id="#+id/rb_bank"
android:layout_marginLeft="40dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:buttonTint="#color/colorPrimaryDark"
android:text="#string/bank"
android:textColor="#color/textColorSecondary"
android:textSize="16sp" />
</LinearLayout>
I'm facing problems with the position of an icon. I've set that icon as drawableLeft of a TextView, this is working fine but, if I set the TextView's gravity to center_horizontal, then a padding space appears between the icon and the text. The code is as follows:
<TextView
style="#style/BaseText.White.Bold"
android:gravity="center_horizontal"
android:drawableStart="#drawable/ic_text"
android:drawableLeft="#drawable/ic_text"
android:text="#string/text"
android:layout_marginBottom="#dimen/margin_small"
android:layout_marginRight="#dimen/margin_big"
android:layout_marginLeft="#dimen/margin_big"
android:padding="0dp"
android:drawablePadding="0dp"/>
What do I have to do to ensure that the icon is shown at the text's left side but horizontally centered?
I've make two screenshots to show you the difference when adding or removing the icon's gravity.
When the textview's gravity is not set, the result is as follows:
But, when the gravity is added, then a padding appears between the text and the icon:
Thanks in advance
Only add android:drawablePadding="10dp" field in your text view refer the coad
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Add New Address"
android:textAppearance="#style/Title"
android:id="#+id/tvAddNewAddress"
android:drawablePadding="20dp"
android:layout_weight="1"
android:padding="5dp"
android:textColor="#color/colorAccent"
android:drawableStart="#android:drawable/arrow_down_float"
/>
Try to give android:gravity="center" to Text View. Also add android:layout_width="wrap_content" and android:layout_height="wrap_content" properties in Text View.
Refer this.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:drawableLeft="#mipmap/ic_launcher"
android:drawablePadding="0dp"
android:drawableStart="#mipmap/ic_launcher"
android:gravity="center"
android:textSize="22sp"
android:padding="0dp"
android:text="TestingTestingTestingTestingTestingTestingTestingTestingTesting" />
</RelativeLayout>
This is what it showing.
I am trying to have a TextView with an ImageView directly to its right. Right now the image partially overlaps the far right of the text, so if the text inputted is long, then the image is "over" the text. I have an ellipse setting on the text but I need the TextView to "stop" right at the left border of the ImageView.
TextView layout settings:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
ImageView layout settings:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
Try this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/iv"
android:singleLine="true"
android:maxLines="1"
android:ellipsize="end"
.... />
<!-- background == #null if you don't want default button background -->
<ImageButton
android:id="#id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_margin="3dp"
android:background="#null"
.... />
</RelativeLayout>
EDIT
See the comments in regards to why this works and the posted question doesn't. Also take a look at
Android Relative Layout alignParentRight and alignParentEnd
for a reference to end/right and start/left attributes.
I'm using mpandroidchart to generate a chart on one-third of my device screen. As I move towards the edge of the screen the TextView gets cutoff by the padding on the sides on the parent container. Is there a way to fix it without changing my UI?
Towards the edge: (gets cutoff)
Away from the edge: (appears good)
marker_view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="#drawable/my_marker">
<TextView
android:id="#+id/textViewMarker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="7dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text=""
android:textSize="12dp"
android:textColor="#android:color/white"
android:ellipsize="end"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
You can apply the
android:clipChildren="false"
android:clipToPadding="false"
on your TextView's parent.
Did you tried gravity attribute?
Try this method to make the text align center.
android:gravity="center"
make sure that, use android:gravity , dont use android:layout_gravity.
here you see the end of my items/groupitems of a listview/expandablelistview.
There are a textview with a Background shape.
I would like to make the textview clickable but ... it is too small ...
Now I would like to span the shape over the whole Background (height) top to bottom
but how to?
<TextView
android:id="#+id/ett"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignRight="#+id/laptop"
android:paddingLeft="5sp"
android:paddingRight="5sp"
android:paddingTop="1sp"
android:paddingBottom="1sp"
android:textSize="17sp"
android:textStyle="bold"
android:textColor="#ffffff"
android:text="Set"
android:background="#drawable/mbutt_setup"
android:focusable="false"
/>
To expand the clickable area of a textview, you can use a touch delegate. It is well explained in the android documentation: http://developer.android.com/training/gestures/viewgroup.html#delegate
Your textview already expand to the whole height of its parent (android:layout_height="match_parent") which mean either the background is not a 9patch (http://developer.android.com/tools/help/draw9patch.html) or the parent of the textview is smaller than the cell height.
The SP dimension should be used for text and not for layout sizes. Consider replacing padding="5sp" with padding="5dp"
Now i have changed the Background from shape to normal Color tag #??????
it seems that textview is parent from groupitemindex or rel. layout
?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/elv_c_g_line">
<TextView
android:id="#+id/laptop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="25dp"
android:textSize="23dp"
/>
<TextView
android:id="#+id/ett"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignRight="#+id/laptop"
android:paddingLeft="5sp"
android:paddingRight="5sp"
android:paddingTop="1sp"
android:paddingBottom="1sp"
android:textSize="17sp"
android:textStyle="bold"
android:textColor="#ffffff"
android:text="Set"
android:background="#33ff33"
android:focusable="false"
/>
</RelativeLayout>
But rel layout is already match parent - so I have not the whole space to cover - the Background auf groupitem is a shape too - no 9pic