Android Studio | paddingLeft and paddingStart not showing on device - android

For some reason the android:paddingLeft and/or android:paddingStart I am using in my layout file is not working when I run it on my device (HTC One M8). I have tried a combination of android:paddingLeft with android:paddingStart, as well as both by themselves.
<EditText
android:id="#+id/editText_Username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_alignStart="#+id/imageView1"
android:layout_alignLeft="#id/imageView1"
android:background="#drawable/textlines"
android:ems="10"
android:hint="#string/username"
android:singleLine="true"
android:paddingLeft="10dp"
android:textColorHint="#color/s_red" />
Here are some links to screenshots that I have taken. (Sorry first post, I do not have the reputation to upload images).
http://imgur.com/a/1nB9X
I have tried using a different device (Samsung Galaxy S4) as well as building it from different systems but I keep getting the same issue.
Any help is greatly appreciated, thank you!
Edit:
As per Kirill's suggestion, I followed this and came up with this in the Activity onCreate function:
EditText pw = (EditText)findViewById(R.id.editText_Password);
EditText un = (EditText)findViewById(R.id.editText_Username);
pw.setPadding(20,0,20,0);
un.setPadding(20,0,20,0);
And it works great, so thank you very much!

android:padding
If you use API 21 - it is a bug.
Look this, may be it can help

Use android:paddingStart instead, it replaces this anyway and fixes this bug.

Related

How to set a TextView to display text in one line in Android

I've set a TextView as the display. I want to display the operation being performed in one line, for example:
9856243187 + 2457896123 - 214583
The problem is, when the input reaches the edge of the TextView - it jumps to the next line.
So, is there anyway to avoid this behavior and keep the input in one line, even if it goes out of the screen?
You should use android:maxLines="1" in your TextView tag.
android:singleLine="true" is deprecated.
android:singleLine="true"
is the answer
Update :
android:singleLine attribute has been deprecated since API Level 3, you can use
android:maxLines="1"
tl;dr:
For new users seeing this question, use android:singleLine="true". Ignore deprecation warnings.
Explanation
According to this bug report, setting android:maxLines="1" may cause your application to crash when some specific values are set in android:ellipsize as well. Apparently it affects most Android devices running 4.1 Jellybean through 6.0.1 Marshmallow (being fixed in 7.0 Nougat). Depending on your device, your mileage may vary. However, if you as a developer are targeting a wide range of devices, it is best to use android:singleLine="true" in order to prevent crashes.
add the code in your Textview
android:singleLine="true"
Thanks guys single line did the tricks but i also had to remove the ellipsis:
android:ellipsize="none"
This code worked for me:
android:singleLine="true"
If you want to manually scroll your single line content then you should use TextView inside HorizontalScrollView
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Single line text view that scrolls automatically if the text is too long to fit in the widget" />
</HorizontalScrollView>
Set the TextView to singeline.
Take a look at this
Can you please try this one ?
<TextView
android:text="Single line text view that scrolls automatically if the text is too long to fit in the widget"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
Hope this will help you.

Padding doesn't work on some devices

I had a strange problems during the set padding to EditText. xml looks like this:
<EditText
android:layout_width="270dp"
android:layout_height="55dp"
android:ems="10"
android:id="#+id/etEmail"
android:textStyle="bold"
android:layout_gravity="center_vertical"
android:textColor="#FFFFFF"
android:hint="Or Use your Email"
android:inputType="textEmailAddress"
android:layout_alignLeft="#+id/textView6"
android:layout_alignStart="#+id/textView6"
android:textColorHint="#FFFFFF"
android:background="#drawable/line_white"
android:paddingLeft="16.5dp"
android:layout_marginTop="10dp"
android:paddingRight="2dp" />
Here is the screenshot from Samsung Note 2 (Android 5.0.1):
... and LG G3 (Android 4.4.2):
As you can see, android:paddingLeft doesn't work for LG.
What could be the reason?
Thanks.
UPD:
Layout bounds (LG):
EditText padding via xml doesn't work after update to API level 21.
But EditText padding works, if it define programmatically.
editText.setPadding(10, 0, 0, 0);
You can track this issue on android issue tracker.
There are some other alternates too, discussed in the issue tracker thread.
I've noticed this on the HTC One X. This doesn't fix your particular issue, but changing paddingStart to paddingLeft worked for me.
This is dpi device problem. Make use of "dimen" folder, give different dp for various device screen sizes. Sure this will solve your problem.
android:paddingLeft="#dimen/yourValueName"

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.

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

Right-align text in a TextView

I have some RTL text (Hebrew) that I want to be aligned right inside the TextView. Currently the XML looks like this:
<TextView
android:id="#+id/textView2"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="right"
android:paddingRight="10dp"
android:singleLine="false"
android:textColor="#FFFFFF"
android:textDirection="rtl"
android:textSize="12sp"
android:textStyle="bold" />
And it acually works great on Galaxy S3 Android 4.2.2 and I even tested it on a Galaxy S1 Android 2.3.3 and it was ok too. But on some devices, for example Galaxy S2 Android 2.3.5, it's aligned left for some reason.
I searched alot and I did not find and solution to this problem, I'd be happy if someone will show me a solution within the XML layout file, but programatcly solution can work as well.
I tired with your code.. you want to placed the text in right side of textview right?...
I'm pretty to help you because, I also gone through this issue..
In your code,
android:gravity="right"
Instead of this, try this
android:gravity="end"
I think this is what you are looking for

Categories

Resources