In Android 2.3.x text is not showing in two lines - android

Here is my code :
<TextView
android:id="#+id/text_view_title"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_margin="5dp"
android:ellipsize="end"
android:maxLines="2"
android:textSize="#dimen/text_size_small" />
In Android version 2.3.2, text is not showing in two lines, while in higher version device the text is showing in 2 lines. Also when I remove the tag ellipsize then text will be shown in 2 lines. How can I solve this issue?

Remove the ellipsize tag. If you really want it for higher versions, add it programatically when you inflate the layout for android versions above 2.3.
Alternatively, use different layouts for 2.3 and before vs 3.0 and later. But that's more likely to lead to maintenance bugs. If this is the only difference I wouldn't go that route.

Related

text ellipsize behavior in android version < 6.0

I have below layout in my xml which will contain 3 TextView and they are aligned left, centre and right respectively.
<RelativeLayout
android:id="#+id/relRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="#string/contact"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/colon"
android:id="#+id/colonRow1"/>
<TextView
android:id="#+id/txtPrimaryContact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_toEndOf="#+id/colonRow3"
android:layout_toRightOf="#+id/colonRow3"
android:ellipsize="end"
android:gravity="end"
android:maxLines="1"
android:text="Joe SmithMartinWilliamCathcsdsdsdadas"/>
</RelativeLayout>
The problem I am facing now is that, the ellipsize doesn't go well or work as expected with android device version < 6.0. I mean for device with Marshmallow version, the ellipsize is breaking the text once max width is reached, but for devices having lollipop or kitkat version, may be lower too, the ellipsize breaks down after space in text and displays ellipses, it does not break for long text.
Here is how it looks in android version less than Marshmallow:
Consider the name is FName LName
Contact : FName...
Here is how it looks in android version greater than Marshmallow:
Contact : FName LNa...
Is this a bug in lower versions or expected behavior. Or is there any other way to do this? I would like to have the Marshmallowversion text in all the devices. Anyway I can achieve this?
Update
Turns out, my assumption was wrong after #Charu's comment. It actually hides out for long text in device version < Marshmallow. How can I come over this?
Right now I've been using below code, but that doesn't scale up when we check with different devices with different screen size. I've attached screenshots for reference.
if(android.os.Build.VERSION.SDK_INT<Build.VERSION_CODES.M && name.length()>20)
name=name.substring(0,20)+"...";
else
txtPrimaryContact.setEllipsize(TextUtils.TruncateAt.END);
>=Marshmallow device
< Marshmallow device [Kitkat to be specific but tested in Lollipop too]
You might tell me that android:singleLine="true" is kind of deprecated that's why you used android:maxLines="1" but trust me adding this android:singleLine="true" to your textView should fix the issue!

Show error for unsupported custom attribute

I am working on an Android Library, which makes buttons of different shapes. The Button's XML looks like this:
<com.singh.daman.mybutton.ShapedButton
android:id="#+id/round"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:fill_color="#color/colorPrimaryDark"
app:button_type="round_rectangle"
app:stroke_color="#color/colorAccent"
app:stroke_width="12sp"
app:text="Round Rectangle"
app:text_size="16sp"
app:text_color="#ffff"
android:layout_gravity="center"
android:background="#null" />
In which attribute app:button_type="round_rectangle" have different values like rectangle, star, circle and round rectangle.
The type round_rectangle is supported by only Lollipop and Above android versions.
So, When the library user sets button_type to round_rectangle and the app minimum android version is less than Lollipop, I want to show an error that it is only supported by api 21 and above, How can I do that?
You need a custom lint rule. I've never done this, but there are writeups from Google on the topic.
http://tools.android.com/tips/lint-custom-rules

Android xml design issues in version 4.1.2

I am working with android tablet's. which has now design issues in various version of android which is looking good in some version's and not looking good in some version's(xml layout designs).
i deployed my app in two different version(4.1.2 and 4.4.2) with same screen size 10 inch
But the result is not same since the design is somehow changed, Checkbox text is not aligned properly in 4.1.2 but 4.4.2 looks better as i expected..
What is the problem in my coding? i have attached the screenshot below and see the checkbox coding for the reference.
<CheckBox
android:id="#+id/rememberme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:button="#drawable/checkboxstate"
android:layout_marginRight="50dp"
android:paddingTop="10dp"
android:text="Remember me "
android:textColor="#000000" />
Helps Appreciated.!
Checkbox padding behaves differently before/after API 17. See this answer for a quick example of how to work around this. The same question contains more discussion of the underlying cause if you are interested.

textview doesn't go multiline

Here's my XML layout example of one of my TextViews which show itself correctly in android 4.2 ... I've downgraded a Nexus S to gingerbread 2.3.6 to test out my application and debug it! Right now, each of my TextViews doesn't take any more space than one line, not even wrapping itself at the end of the first line. (On 4.2, the example below was taking 3 lines and was adding "..." at the end if there was some text missing!)
How can I make my textViews compatible with gingerbread? Thank you!
<TextView
android:id="#+id/TV_guideRow_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/TV_guideRow_title"
android:layout_below="#+id/TV_guideRow_title"
android:text="blabla text that could go up to 3 lines"
android:textColor="#3BB9FF"
android:layout_alignParentRight="true"
android:layout_above="#+id/TV_guideRow_more"
android:layout_marginRight="8dp"
android:layout_marginBottom="3dp"
android:ellipsize="end"
android:maxLines="3"/>
You want:
android:inputType="text|textMultiLine"
Also, depending on the parent of that TextView, multiline may not render properly. Try manually setting the height to, say, 100dp and see if that works.
After some more investigation, I've found out that all my related textView problems were related to my custom theme, which was made for android 4.0+ (since Holo was used as the base theme)
I've set the APIs which doesn't have holo to use the "Light" theme and everything is showing up correctly without any further modification.

Vertical text spacing changed in Android 4.0

I have an app that allows the user to change the text size. On Android 2.X when you made the text smaller the vertical spacing got smaller too. On 4.X the text gets smaller and the spacing remains the same.
The call that I am using to change the size is (there is a loop to change multiple lines):
tvData[i].setTextSize(TypedValue.COMPLEX_UNIT_PX, fSize);
The text fields are described in main.xml as follows (there is more than one and they are each "below" the previous one.
<TextView android:id="#+id/textOut1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:typeface="monospace"
android:textSize="28dip"
android:textColor="#000000"
android:textStyle="bold"
android:layout_below="#id/textOut0"
/>
What do I have to do so this works in both old and new Android?
The fix was to not put each line of text in a separate TextView. By putting all of the text in one TextView and ending each line in a newline it now adjusts vertical spacing when the font size is changed.
And the change to one has been tested to work on older versions of Android too.
I cannot remember why I used an array of TextViews in the first place, seems like a bad choice looking at it now, but it did work with older versions.
TomZ

Categories

Resources