What is required to use android:backgroundTint in Android - android

I'm really confusing how the android's design/front-end works. A lot of questions are in my mind that, why android not provider easy way/method ( as in html like border-bottom, or in JavaFX) to add borders in textview or something other blah blah. but afraid may be stackoverflow not allowed me ask such question. One question of them which I want to ask here is that what is required to use android:backgroundTint
Because in the EditText it is working as simple.
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Edting"
android:backgroundTint="#00FFFF"
/>
but in the TextView to work with it or to add the border I have to use a drawable utility.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Edting"
android:backgroundTint="#00FFFF" // not working at all
/>
Somewhere I read that it add the shade to background. But why it is changing the bottom-border. So another question could be the actual purpose of android:backgroundTint

Related

Android studio layouts howto make prompt/hint before EdiText

I am working in a kotlin project, and have been searching for some documentation about the screen layout.
What i want to do is very rudimentairy i guess. I want is to put a label/prompt/text before a EditText.
In html i would program something like this:
<form>
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
</form>
And get the a result like this:
First name: ___________
All i can find is a "android:hint=". But it only fills the View if there is nothing in it.
Should one add extra (plainText) elements for each label ? and how should one contstrain it to the EditText ? or is there some kind of grouping ?
Update after received answers
After reading the answers i understand that you have to roll your own solution. (I am still fighting with androidstudio because it sorts the xml elements so they are not always where i put them.)
I do not use a TextInputLayout (i hope this is allowed) which makes it all quite simple. So this is my solution for now:
We link the TextView ("Date of Birth") to the parent layout:
<TextView
android:id="#+id/dobLabel2"
android:layout_width="92dp"
android:layout_height="23dp"
android:layout_marginStart="76dp"
android:layout_marginBottom="112dp"
android:labelFor="#id/dobInputText"
android:text="Date of Birth"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
and we link the EditText to the TextView
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/dobInputText"
android:layout_width="240dp"
android:layout_height="54dp"
android:hint="Day/Month/Year"
app:layout_constraintStart_toStartOf="#+id/dobLabel2"
app:layout_constraintTop_toBottomOf="#+id/dobLabel2" />
If you play with the layout_contraints you can position the the EditText also to the left of the label.
Thanks for all the input, i think i can solve my problem now.
Android EditText (now often used as a combination of TextInputLayout containing one (and only one) TextInputEditText) can display a Hint, but only while the view has no focus/content.
If you want to provide a better description on what a particular EditText is for, for many reasons (accessibility, often neglected, is not the only one), you may want to provide an extra TextView positioned anywhere you consider it ok to add the extra information needed to better describe the EditText.
The main thing to keep in mind, is to provide this TextView with the labelFor attribute, as described in the Android documentation.
If you're reading this and wondering but why do I have to provide an extra Textview to describe, why not just use the hint, android is horrible!!!, keep in mind that the Hint is good for different reasons, but not for describing what the field is about.
E.g.: Imagine you're asking for a Date of Birth. You may be tempted to write this: (note this is a simplified version obviously):
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/dobInputLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/dobInputText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Date of Birth" />
</com.google.android.material.textfield.TextInputLayout>
And you'd be mostly ok, but then your designer comes in and says, well, we also want to show the Format that we accept, for e.g.: DAY/MONTH/YEAR...
Now you're going to change the hint to be:
android:hint="Date of Birth (DD/MM/YYYY)
And you'd again, be ok, but for accessibility users... this doesn't read very efficiently nor is very clear. You also get back from your designer who says: "but I don't want the (DD/MM/YYYY) part to be visible after the user focuses or types something..."
And so on and so forth.
The correct (according to Google, Material Design, and who knows what), is to provide an extra TextView that accompanies the TextInput combos:
(again, keep in mind this is pseudo-code, when in doubt, read the documentation)
<TextView
android:id="#+id/dobLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date of Birth"
android:labelFor="#id/dobInputText />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/dobInputLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/dobInputText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Day/Month/Year" />
</com.google.android.material.textfield.TextInputLayout>
Do not provide contentDescription on those views because they will likely interfere with TalkBack/Accessibility. These are the conventions that Android set in place, you may or may not like them, but this is how it's expected to be done.
Do I think EditText should be a better widget and handle this better for you? Yes. Does it matter what I think? Nope.
Yes, you have to add one more textview before adding edit text. The hint is used for displaying messages in edittext.

Android - Ellipsize not working for a link in TextView

I'm a newbie to Android and I have looked at similar questions asked by others without a definite answer, since, I think, my problem is a bit different.
I'm using a TextView in my program in which there can be links, text, numbers etc. following is the TextView I'm using.
<TextView
android:id="#+id/viewText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:autoLink="web"
android:linksClickable="false"
android:ellipsize="end"
android:maxLines="7" />
Although this is working for normal texts, the ellipsize does not work whenever links are present in the TextView. I'm using "autoLink" in order to show the user that it is link but had set android:linksClickable to false. Right now, I've added the ellipsize from the code but I want to know whether I can do it from the XML file itself.
Thank you.

Styling the custom switch in android

I am trying to create a listview with switches. It is working; but not as how i expected it to be. The text ON/OFF is written inside the circle(slider) and not behind it which looks awkward. I cannot find a way on how to put the text behind the slider and i tried searching but it seems that no one is experiencing this problem aside from me.
Also, is there a way where i can edit the custom switch or am i obliged to use android:background like what others are doing base on my research. (I am avoiding to use background because i am not good at Photoshop).
Thank you in advance!
You can have 9 patch images for switch
<Switch
android:id="#+id/switch_bg2"
android:layout_width="92dp"
android:layout_height="24dp"
android:checked="true"
android:focusable="false"
android:textOff="O"
android:textOn="I"
android:thumb="#drawable/switch_thumb"
android:track="#drawable/switch_bg"
android:typeface="sans" />

Android 4.3+, android:textColorHint doesn't work, hint color is always white

As the question says: When testing the app on devices running Android 4.3+ (also tested on 4.4), the color of the hints (for EditText) turns white, and no matter what color I set it to, it remains white. Since the EditText's background is white, the hints isn't visible to the naked eye!
I've googled and googled and can't find anyone having the same issue. The app was built using android:minSdkVersion="8" and android:targetSdkVersion="15". The EditText looks like this:
<EditText
android:id="#+id/editText3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/my_background"
android:ems="10"
android:textColorHint="#color/BlueViolet"
android:hint="#string/my_hint"
android:inputType="number"
android:tag="21_0" />
At first it was using the default android:textColorHint and I thought that maybe Android 4.3+ changed the default to white for some reason. But that doesn't seem to be the case since whatever color I set it to, it's always white.
I'm aware that fill_parent is deprecated, but the app was build quite some time ago, but is now unuseable due to hints disappearing. Any help is appreciated! Thanks!
EDIT:
The 'error' seem to occur when using a String-resource for hint. This works: android:hint="Hello world" while this doesn't android:hint="#string/my_hint"
For who struggles with same problem;
If you used your edittext in
android.support.design.widget.TextInputLayout
you should put your
android:textColorHint="#color/BlueViolet"
in TextInputLayout
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColorHint="#android:color/white">
<AutoCompleteTextView
android:id="#id/etextEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_card"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true"
android:textColor="#android:color/white"/>
</android.support.design.widget.TextInputLayout>
It seems since Android 4.3+ it's no longer possible to make String-resources as follows (not sure if it was ever meant to work this way though):
<string name="my_hint"><font size="13" fgcolor="#ffbbbbbb">Hello world</font></string>
If you do, they turn out white. So you are stuck with creating the String-resource this way:
<string name="my_hint">Hello world</string>
And then use the properties on the TextView/EditText to edit the color of the hint. To change the size, it seems it's still possible to do:
<string name="my_hint"><small><small>Hello world</small></small></string>
I found this out by reading the comment of this answer: https://stackoverflow.com/a/11577658/2422321, by Edward Falk
In addition to Erhan's answer or incase you are using the TextInputLayout widget,
I found that using app:hintTextColor instead of android:textColorHint works best

How to make a checkbox look better in android

This is my XML for my check box:
<CheckBox
android:id="#+id/atm_checkbox"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#color/input_color" />
And it looks like this:
http://imageshack.us/photo/my-images/528/47342915.png/
This is what i found on internet:
<CheckBox
android:id="#+id/chkAndroid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/chk_android"
android:checked="true" />
which looks like this
how to change my checkbox to look like the one i found on internet.
As my rep is <10 i cant upload image of my checkbox, or can anyone help me how to style checkbox to make it look better
I think both the xmls have similar code, but why are they looking so different?
If you want custom the look of checkbox see this tutorial and find everything.
By the way, the checkbox from your link is for Android3.0 and above.
CheckBox derive from Button class, so you can set a background image like button. See this link, may be it is what you are looking for.
If you want a clean design without codes, use:
<CheckBox
android:id="#+id/checkBox1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:drawableLeft="#android:color/transparent"
android:drawablePadding="10dp"
android:text="CheckBox"/>
The trick is to set colour to transparent for android:drawableLeft and assign a value for android:drawablePadding. Also, transparency allows you to use this technique on any background colour without the side effect - like colour mismatch.

Categories

Resources