How to character-wrap in Android textview without using singleline? - android

I have a textview in xml file. When a text is set in java file, if the 2nd String is too long, for example: "Hello Worlddddddddddddddddddddddddddddddddddddddddddddd", the 2nd word is not visible. It should be only one line and should not use the android:singleLine How can I solve it? Thanks in advance for the help. :)
<TextView
android:id="#+id/txtItemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:maxLines="1"
android:textColor="#color/white" />

if you without using singline, you can set height and weight.
android:scrollHorizontally="false"
ex :
<TextView
android:id="#+id/text"
android:text="#string/hello_world"
android:layout_width="wrap_content"
android:scrollHorizontally="false"
android:layout_height="15dp"/>

Use the XML below or refer to this SO article as this is what you really need.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:ellipsize="end"
android:singleLine="true"
android:gravity="right|center_vertical"
android:maxLines="1"/>

You can use elipsize property of textview
<TextView
android:id="#+id/txtItemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:maxLines="1"
android:textColor="#color/white"
android:ellipsize="end" />

Related

How to ellipsize a TextView in between an ImageView and a TextView?

Here is my layout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="65dp"
android:layout_marginStart="20dp"
android:gravity="center_vertical|start"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="18.9dp"
android:lineSpacingExtra="64sp"
android:textColor="#484848"
android:textSize="16sp"
tools:text="அனைத்து அனைத்துஅனைத்து" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:lineSpacingExtra="64sp"
android:text="0"
android:textAlignment="center"
android:textColor="#color/red_500"
android:textSize="14sp" />
</LinearLayout>
All other languages are working fine, except tamil language is very big.
I need an icon at beginning and sometimes it show number of notifications at end. So I need to set ellipsize to text on middle.
How to achieve this?
you can use android:ellipsize atrribute to do that.
like this :
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="18.9dp"
android:lineSpacingExtra="64sp"
android:textColor="#484848"
android:textSize="16sp"
android:ellipsize="end"
android:maxLines="1"
tools:text="அனைத்து அனைத்துஅனைத்து" />
note: don't forget to use android:maxLines attribute to set the line number of your text.

TextView new line (in multiline) issues

currently I am getting this result for a multiLine text view -
maxLines = 2
If text is -
Hello hfhfhfhfhfhfhhfhfhfhfhfhhfhfhf
Then output is :
But I need it like this :
Please help me to get this result :)
XML is
<TextView
android:id="#+id/user_name"
style="#style/default_text_font_face"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:scrollHorizontally="true"
android:maxLines="2"
android:text="Hello hffffffhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhhfhfhhfhfhfhfhhfhfhfhhfhfhfhfhhfhfhfhfhhfhfhfhfhhfhfhfhfhhfhf"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white" />
Use
android:layout_width="match_parent"
to your TextView
EDIT1
Try the following way
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#535353"
android:textColor="#ffffff"
android:maxLines="2"
android:text="Best Effffffffffffffffffffffffffffffff\nfffffffffffffffffffffffffffffffffffffff"
android:textSize="20dp"/>
</LinearLayout>
Output
I hope this may helps you
you have use below property..
android:maxWidth="size"
Replace the size with the size you prefer. For example, 100dip.
UpDate :
xml file
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:maxLines="2"
android:maxWidth="50dip"
android:text="Best Efffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15dp" />
Output :
UpDate 2 :
using match_parent.
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="50dp"
android:maxLines="2"
android:maxWidth="50dip"
android:text="Best Efffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15dp" />
output :

How to underline text in Android Studio?

Looked everywhere, couldnt find a solution for this. Setting bold or italic is very easy, why is setting underline not as easy?
Here's my bit of relevant code:
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/forgotpasswordHolder"
android:layout_marginTop="10dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Forgot your password?"
android:id="#+id/labForgotpassword"
android:textColor="#6BB08C"
android:layout_weight="1"
android:textStyle="bold|italic"
android:layout_gravity="left"
android:paddingLeft="20dp"
android:textIsSelectable="true"
android:singleLine="false" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Not a member?"
android:id="#+id/signup"
android:textColor="#6BB08C"
android:layout_weight="1"
android:textStyle="bold|italic"
android:singleLine="false"
android:layout_gravity="right"
android:gravity="right"
android:paddingRight="20dp"
android:textIsSelectable="true" />
</LinearLayout>
I have two "Forgot your password? and a "Not a member?" buttons, and I'd love it if I could underline the text(s).
Thanks in advance!
Use a string resource with <u> tags, like this
android:text="#string/forgotPassword"
Then in strings.xml, create a String
<string name="forgotPassword"><u>Forgot your password?</u></string>
Just create a View below the TextView
As an example...

Android TextView Not Wraping up the text for hindi text

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" />

TextView bold via XML file?

Is there a way to bold the text in a TextView via XML?
<TextView
android:textSize="12dip"
android:textAppearance="bold" -> ??
</TextView>
Thanks
I have a project in which I have the following TextView :
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="#string/app_name"
android:layout_gravity="center"
/>
So, I'm guessing you need to use android:textStyle
just use
android:textStyle="bold"
Example:
use: android:textStyle="bold"
<TextView
android:id="#+id/txtVelocidade"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/txtlatitude"
android:layout_centerHorizontal="true"
android:layout_marginBottom="34dp"
android:textStyle="bold"
android:text="Aguardando GPS"
android:textAppearance="?android:attr/textAppearanceLarge" />
Use android:textStyle="bold"
4 ways to make Android TextView Bold
like this
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="12dip"
android:textStyle="bold"
/>
There are many ways to make Android TextView bold.
use textstyle property as bold
android:textStyle = "bold";
Just you need to use
//for bold
android:textStyle="bold"
//for italic
android:textStyle="italic"
//for normal
android:textStyle="normal"
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="#string/userName"
android:layout_gravity="left"
android:textSize="16sp"
/>

Categories

Resources