Styling text on a DialogFragment - android

I have a simple DialogFragment which shows a bit of text (which contains a Year string) and then a SeekBar that the user can slide and change the Year string.
On Android 3 and 4 this looks right... those platforms have a light background and use black text.
However, on Android 2, the dialog has a dark background and is still using black text.
I don't want to have to configure different color schemes for different versions of Android because there has GOT to be some default values built into the Android system that I should be able to use to style my TextView so that it uses the appropriate text color.
Here is my TextView that displays the year string:
<TextView
android:id="#+id/textViewYear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="1976"
android:textAppearance="?android:attr/textAppearanceLarge" />
What settings can I apply to my TextView so that it will always be appropriately colored by the system?
Note, I can't just use an Inverse style, because on Android 3 and 4 it is working properly. If I use an Inverse text appearance then it works on Android 2, but fails on 3 and 4.

I found the solution on another SO post:
builder.setInverseBackgroundForced(true)
On Android 3.x and 4.x this doesn't seem to change anything, but on Android 2.x it inverts the color scheme so that the background is white so the black text shows up properly.

Related

Changing color of Android icon

All of the Android material icons come in either black or white:
https://www.google.com/design/icons/index.html
Which I add to my layout like:
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/ic_plus" />
Is there a way to change the color of the icon from black/white to something else in the layout/code?
I've heard of the android:backgroundTint="#color/green" property, but does this work across all versions of Android? For example, if I use this property in my layout, will it change the color on Android versions older than 5.0?
Edit: Wow, you guys are good at making a new user feel unwelcome.
I think, It is not possible to all android versions.
you can design icon color in this website.()
Note: Google Designs icons also available in this website.
Icon generators allow you to quickly and easily generate icons from existing source images, clipart, or text.
http://romannurik.github.io/AndroidAssetStudio/

Android 5.0 makes unselected checkboxes invisible when background is white

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"

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

How can I get the native Android Editbox

I have created an Editbox in XML using this code:
<EditText
android:id="#+id/txtEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="50dp"
android:inputType="textEmailAddress" >
</EditText>
The textbox renders like this:
How can I get the native android EditText with the orange borders when focused, white background etc. ?
I tried adding
android:background="#android:color/white"
but that only changes the background to white.
The style you are seeing is "native" for the Honeycomb (3.0) Android version, specifically, the new Holo-dark theme. The orange-borders-and-white-background look was last used in 2.3.* and has since been left behind.
Agree with the answer of neutrino: The style you are seeing is "native" for the Honeycomb (3.0) Android version, specifically, the new Holo-dark theme.
But still if you wants the EditText that you want then you need to set the style/theme inside the AndroidManifest.xml file:
<activity android:theme="#android:style/Theme.Light">
when we add view's from layout, it renders from framework, then add the properties we provided . so in your code, EditText is native EditText, which varies from device to device . so if you want look and feel over a particular device make your own style for that and use it .
Had the same problem...
Try using:
EditText usr=(EditText)findViewById(R.id.editText1);
usr.setBackgroundResource(17301528);
If you really want to older versions of the EditText iamges (from sdk/android-8/platforms/data/res folder), place thema in the drawable folder, create a StateListDrawable out of it, and set the background of the EditText as that Drawable. But why bother ? Let app users enjoy the default look and feel of their device.

Categories

Resources