Check This Image:
<TextView
android:id="#+id/cusumerName"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:paddingLeft="10dp"
android:background="#drawable/button"
android:hint="Consumer Name"
android:textColor="#660000"
android:textSize="15sp" >
</TextView>
Here I found Text hint on Top, I want it vertically, How can I do?
use this in xml of TextView:
android:hint="H\ne\nl\nl\no"
Related
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2"
android:background="#ffffff">
<TextView
android:id="#+id/sorttxt"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="0.995"
android:text="Sort"
android:textSize="17dp"
android:textColor="#000000"
android:background="#25a65b"
android:drawableLeft="#drawable/leftImagesort"
android:gravity="center"
/>
<View
android:layout_width="0dp"
android:layout_height="40dp"
android:background="#color/grey_5"
android:layout_weight="0.01" />
<TextView
android:id="#+id/filtertxt"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="0.995"
android:text="Sort"
android:textSize="17dp"
android:textColor="#000000"
android:background="#25a65b"
android:drawableLeft="#drawable/leftImagefilter"
android:gravity="center"
/>
I am using above code but wants to remove gap between image and text i have used android:drawableLeft to insert image in textview
right now i am getting output shown in image
Set attribute android:gravity="left" instead of android:gravity="center" in both TextView
If you are using drawable left for showing image and you want to remove gap between image and text then you need to use android:drawablePadding="-20dp". you need to give drawablePadding in minus.
You can use like :
android:drawableLeft="#mipmap/ic_launcher"
android:drawablePadding="-20dp"
set drawablePadding="0dp" and android:gravity="left|center"
In my app i need to reduce the buton size if i did that the text of the button cannot displayed on that button. so how to align the text inside the button
this is my button.xml code
<Button
android:id="#+id/intro_button"
android:layout_width="560dp"
android:layout_height="80dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:background="#drawable/button_shape"
android:gravity="center_horizontal"
android:padding="50dp"
android:text="#string/Introduction"
android:textSize="10dp"/>
this is String.xml code
<string name="Introduction"></string>
If you reduce the button size, you have reduce the padding too.
<Button
android:id="#+id/intro_button"
android:layout_width="560dp"
android:layout_height="80dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:gravity="center_horizontal"
android:padding="30dp"
android:text="Introduction"
android:textSize="10dp"/>
Use a TextView,
set a background with some padding:
<TextView
android:id="#+id/intro_button"
android:layout_width="560dp"
android:layout_height="80dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:background="#drawable/button_shape"
android:gravity="center_horizontal"
android:padding="50dp"
android:text="#string/Introduction"
android:textSize="10dp"/>
Then, in your java file, find your textview using the id and set an OnClickListener on it
Use this,
Depending on your Text and textSize Button will Create:
<Button
android:id="#+id/intro_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:background="#drawable/button_shape"
android:gravity="center_horizontal"
android:padding="50dp"
android:textColor="#color/colorPrimary"
android:text="stringIntroduction"
android:textSize="20dp"/>
In my case adding android:padding="50dp" also added space on the whole button , so i just wanted to add some extra space on the right/left so that text didn't overlap with the button layout:
android:paddingRight="5dp"
android:paddingLeft="5dp"
i've an edittext :
<EditText android:id="#+id/chp"
android:layout_width="match_parent"
android:paddingLeft="10dp"
android:layout_height="340dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:gravity="top"
android:hint="#string/hintCommentaire"
android:textSize="25sp"
android:drawablePadding="10dp"
android:drawableLeft="#drawable/ic_comment"
android:layout_margin="5dp" />
The problem is, i've my hint at the top of the edittext, but the drawable stays in the center..
I tried with "drawableStart", but it's not working.
Someone to help me ?
EDIT : I want the text and drawable in the top(same line). (i want to keep the height of my edittext)
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/etMobile"
android:hint="Mobile"
android:fontFamily="sans-serif-normal"
android:singleLine="true"
android:textSize="15sp"
android:gravity="center|start"
android:textCursorDrawable="#null"
android:drawableStart="#drawable/ic_profile_bio"
android:drawablePadding="10dp"
app:met_floatingLabel="normal"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp" />
Set this Property android:gravity="center|start" in above EditText
Currently I faced a problem in an application when I was trying to display text on text view which is HINDI font text on a textView it does not wrap it. It look like
My TextView code is
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center_horizontal"
android:padding="10dp"
android:textSize="19sp"
android:textColor="#android:color/white" />
Can anyone help me to solve this problem?
Try following properly for TextView
android:maxLines="2"
Add this for your TextView:
android:ellipsize="none"
android:singleLine="false"
Try this..
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center_horizontal"
android:padding="10dp"
android:textSize="19sp"
android:layout_weight="1"
android:ellipsize="none"
android:maxLines="100"
android:scrollHorizontally="false"
android:textColor="#android:color/white" />
I want to make the multiline text auto scroll down as I add in more text:
<EditText
android:id="#+id/Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/TypeBox"
android:layout_below="#+id/ReceiverName"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_weight="0.65"
android:ems="10"
android:focusable="false"
android:gravity="bottom"
android:inputType="textMultiLine|textNoSuggestions" >
</EditText>
I have tried searching for it but all i could find is auto scroll of a text box within a scroll view.
android:inputType="textMultiLine"
android:editable="true"
android:enabled="true"
android:minLines="6"
android:maxLines="6"
android:isScrollContainer="true"
android:focusable="true"
Refer this link for more info
https://alvinalexander.com/source-code/android/android-edittext-isscrollcontainer-example-how-make-multiline-scrolling
I think, you need to add a line:
android:inputType="textFilter|textMultiLine|textNoSuggestions"
Add bellow code in activity onCreate(), this Add scroll behavior to
text view
textView.setMovementMbehavior ScrollingMovementMethod());
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:text="text"
android:textColor="#ffffff"
android:textSize="20sp"/>