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.
Related
I have some EditText and TextView inside a Fragment. On the XML layout of the fragment I have added the following in EditText and TextView:
android:textAlignment="center"
Then I have tested the app in the emulator, on virtual device with API 25, and all seems to work fine, the fragment is displayed as it looks in the design window, with the text centered in both the EditText and the TextView.
However, I have launched the app in my own phone Android 4.1.2 API 16 and also in another virtual device that I have also created with API 16 and now none of the 'EditText' or 'TextView' are respecting the textAlignment property, the text is just displayed aligned to the left side.
Any help?, I am looking around but I cannot find anything related to API 16 and problems like that with alignments.
You should use
android:gravity="center"
Place the object in the center of its container in both the vertical
and horizontal axis, not changing its size.
You can easily do that with below. As i mentioned in comment also.
<EditText
android:id="#+id/et_bio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:ems="10"
android:gravity="center"
android:hint="Bio DAte aaaaaaaa"
android:imeOptions="actionDone"
android:inputType="text"
android:maxLines="3"
tools:ignore="RtlCompat" />
Check official documentation.
android:textAlignment="center" or its setter were introduced in API 17. So it won't work on earlier devices i.e. API 16.
Instead use android:gravity which should provide the same functionality both in EditText and TextView.
I have an android app that has been working fine pre-Android 5.0. With the update, I noticed that checkboxes and radiobuttons placed on white backgrounds are not visible if they are not selected. For example, this is what a checkbox looks selected and unselected in jellybean:
As you can see, there is a light gray square when the checkbox is not selected. However, after updating to lollipop, this is what it looks like:
So, as you can see, there is no gray square or anything that suggests there is a checkbox here. The same problem happens with radiobuttons. I really don't want to go trough the pain of creating new drawables just for this simple ting. I have seen that checkboxes within the accessibility menu of android 5 have a nice square, but haven't figured out how to make mine look the same:
I tried creating a new android project and just adding some checkboxes and radio buttons with a white background, but they are still invisible when unchecked. I'm using xamarin studio and c#, if that makes any difference. Anyway, I'll understand any java code you post.
This is what my checkbox code looks like:
<CheckBox
android:layout_width="wrap_content"
android:layout_height="0dp"
android:id="#+id/chkSeleccionar"
android:layout_gravity="right"
android:gravity="center_vertical"
android:clickable="false"
android:focusable="false"
android:scaleX="1.5"
android:scaleY="1.3"
android:layout_weight="50"
/>
I couldn't get the theme working, but what did work for me was the following:
android:button="#drawable/abc_btn_check_material"
android:buttonTint="#color/red"
Put this into your CheckBox XML layout.
Just change the
android:buttonTint="YOUR COLOR"
It works.
Make sure you are using a Material theme for Android 5.0 devices - this will ensure you're styling remains consistent with other components. Look for an android:theme element in your AndroidManifest.xml file (either on your application or on an individual activity), then look up what style is set there and check the parent attribute for the style.
Add this attribute
android:buttonTint="#EEEEEE"
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.
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
Working in Eclipse, I am trying to put some italics text onto a layout. The problem is, that when I am setting
android:textStyle="italic", the text disappears. (The height of content becomes 0 and the whole TextView becomes invisible.) Bold works OK. I have tried every typeface, but the result is the same.
On the device it shows itself in italics OK. But the layout is very complicated and its design without seeing it becomes very complicated, too.
Here is the TextView
<TextView
android:id="#+id/smallEpgNextProgramTime"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
android:layout_margin="10dp"
android:gravity="left|top"
android:textSize="35dp"
android:typeface="monospace"
android:textStyle="italic"
android:text="12:00-13:11"
/>
Android version is 2.3.3. Eclipse version is 2.6.
It is even worse. If I leave italics there, after some changes of layout view to graphics and back to text, Eclipse works slower and slower and hangs up the PC. So, I have to put it as "normal" in layout and to set textStyle by code. A bad bug it is!
I think its an android platform issue.
Look at Issue 22867: Incorrect layout preview when ITALIC text style used
It doesn't show up on the layout's graphical representation but works correctly when you build and run the app.
Update:
If you want to preview for designing xml layout then just use
android:typeface="serif"
In this android:textStyle="italic" works. And text will displayed in italic style in graphical layout editor.
Its only works for this serif typeface.
you can use this
TextView txtView;
txtView=(TextView)findViewById(R.id.smallEpgNextProgramTime);
txtView.setText(Html.fromHtml("Restaurant <i><b>Hello</b></i>"));
What u wrote is 100% correct if you want to write in code you can use this..
textView.setTypeface(null, Typeface.ITALIC);
textView.setText(editText.getText().toString());