I want to have a single lined TextView to show up 3 dots at the end when the text is longer than the TextView. I don't know why - but I don't get it.
I already wrapped my head around similar StackOverflow questions, but I ended up with no solution. Maybe someone has some useful hints.
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical">
<TextView
android:textStyle="bold"
android:text="Full Name"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_width="wrap_content"
android:id="#+id/lName"
android:layout_gravity="center_vertical"
android:maxLines="1"
android:ellipsize="end"/>
</LinearLayout>
The LinearLayout above is nested into 2 other LinearLayouts. Maybe this is important to know. I already tried the attribute "singleLine" too, but some say this is deprecated and it doesnt work anyway.
Add the following styles in your styles file (typically styles.xml):
<style name="autoscroll">
<item name="android:singleLine">true</item>
<item name="android:ellipsize">marquee</item>
<item name="android:marqueeRepeatLimit">marquee_forever</item>
<item name="android:focusable">true</item>
<item name="android:focusableInTouchMode">true</item>
<item name="android:scrollHorizontally">true</item>
</style>
Then add the style #style/autoscroll to your TextView:
<TextView android:id="#+id/lName"
style="#style/autoscroll" />
You can reuse your autoscroll feature easily when you want this way.
Add this in your xml for the TextView:
android:maxWidth="200dp"
android:maxLines="1"
As
android:singleLine="true"
is deprecated.
android:id="#+id/lName" android:layout_width="150dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:text="Avinljhakjhsajkhakjshda"
android:textSize="16sp"
This doesn't work with me unless adding 'android:ems' attribute along with the android:ellipsize attribute
android:ellipsize="end"
android:singleLine="true"
android:ems="8"
The ellipses did not appear while my text was selectable.
I needed to disable selectable text (which is the default):
android:layout_width="0dp" (match constraint)
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textIsSelectable="false"
It works with singleLine="true" but this attribute is now deprecated, use ellipsize and scrollHorizontally="true" instead.
Use this code it will definitely work.
<TextView
android:id="#+id/sAddress"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
android:text="Adress"
android:textSize="14sp"/>
Related
I'm experiencing a problem with the AutoCompleteTextView dropdown component.
As you can see from the image below, there are those black borders inside the popup that I cannot get rid of.
Black borders:
I'm an Android noob, and I already tried basically everything with any success.
Below the code, I'm using.
activity.xml:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:hint="Categoria"
android:layout_marginRight="#dimen/spacing_xlarge"
app:hintEnabled="true"
app:boxBackgroundColor="#color/white"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu">
<AutoCompleteTextView
android:dropDownSelector="#color/white"
android:id="#+id/private_place_dropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dropDownHeight="300dp"
android:inputType="none"
android:drawableTint="#color/white"
android:backgroundTint="#color/white"
android:editable="false"
android:textColor="#color/piumaBaseColor"
/>
</com.google.android.material.textfield.TextInputLayout>
dropdown_menu_popup_item.xml:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:paddingLeft="#dimen/spacing_medium"
android:paddingRight="#dimen/spacing_medium"
android:paddingBottom="#dimen/spacing_medium"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="#style/TextAppearance.MaterialComponents.Body1"
android:gravity="center_vertical"
android:background="#color/white"
android:backgroundTint="#color/white"
android:textColor="#color/grey_extradark"
android:text="test"/>
Can you please help me? Thank you a lot!
This dark lined are additional background from PopupBackgroundView. For fix the issue just use for background the same surfaceColor as you have in your theme
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
...
<item name="colorSurface">#FFFFFF</item>
</style>
I am setting style,color and size to textview , that is working
this is my code `
<android.support.v7.widget.AppCompatTextView
android:id="#+id/txt_agent_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:gravity="center"
android:textColor="#000"
android:textSize="14sp"
android:textStyle="italic"/>
Please check your parent layout is correct some times transparent layer or such things create visualise problem with colour
<android.support.v7.widget.AppCompatTextView
android:id="#+id/txt_agent_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="10dp"
android:gravity="center"
android:text="AppCompatTextView"
android:textColor="#FFFFFF"
android:textSize="114dp"
android:textStyle="italic" />
Use Dimension for setting up a text size ,always avoid hard coding
If you want to set same style for text-color,text-size and text-style than you can create something like
<style name="MyTextAppearance" parent="TextAppearance.AppCompat">
<item name="android:textColor">?android:textColorPrimary</item>
<item name="android:textSize">#dimen/abc_text_size_body_1_material</item>
<item name="textColor">?textColorPrimary</item>
<item name="textStyle">italic</item>
</style>
I want to know why my autocomplete textview suggestion is hiding the autocomplete textview , i am attaching the picture for better understanding.
<AutoCompleteTextView
android:id="#+id/current_location"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/round_background_white"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:paddingLeft="5dp"
android:completionThreshold="1"
android:dropDownHeight="80dp"
android:dropDownWidth="wrap_content"
android:singleLine="true"
android:focusable="true"
android:textColor="#000000"
android:textColorHint="#000000"
android:dropDownListViewStyle="#style/DropDownListViewStyle"/>
Style.xml:
<style name="DropDownListViewStyle">
<item name="android:dividerHeight">2dp</item>
</style>
It's probably due to the custom drawable round_background_white.
Make sure you are specifying enough height & padding in it.
Also post your round_background_white over here.
I'm using a TextInputLayout wrapped around an EditText. Right now the counter is black, I'd like it to be white. I'm not sure what option to set to get it to be white.
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:counterEnabled="true"
android:textColor="#color/white"
android:textColorHint="#color/white"
>
<EditText
android:id="#+id/myfield"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#color/white"
android:hint="#string/myfield_hint"
android:inputType="text"
android:maxLength="26"
android:textColor="#color/white"
android:textColorHint="#color/white"/>
</android.support.design.widget.TextInputLayout>
I decided to write this answer based on comments from previous one.
At first, you need to create the style for your counter, for example:
<style name="CounterStyle" parent="TextAppearance.AppCompat.Small">
<item name="android:textColor">#android:color/white</item>
<!--other parameters that you want to change -->
</style>
Then add this style to TextInputLayout:
app:counterTextAppearance="#style/CounterStyle"
That's all, it should works. Full code:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:counterEnabled="true"
app:counterTextAppearance="#style/CounterStyle"
android:textColor="#color/white"
android:textColorHint="#color/white">
<EditText
android:id="#+id/myfield"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#color/white"
android:hint="#string/myfield_hint"
android:inputType="text"
android:maxLength="26"
android:textColor="#color/white"
android:textColorHint="#color/white"/>
</android.support.design.widget.TextInputLayout>
You can also use some style for the overflow counter:
app:counterOverflowTextAppearance="#style/YourOverflowTextStyleHere"
As described here (thanks #Sufian for the link)
Please add:
app:counterTextAppearance="#android:color/white"
to your TextInputLayout.
Hope this helps!
My login screen locks like this
http://pbrd.co/UVekFg
with that code
<TextView
android:id="#+id/login_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:text="#string/login_label_text" />
<EditText
android:id="#+id/username"
android:layout_width="#dimen/textfield_width"
android:layout_height="#dimen/textfield_height"
android:background="#drawable/textfeld"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/login_password_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/password" />
<EditText
android:id="#+id/login_password"
android:layout_width="#dimen/textfield_width"
android:layout_height="#dimen/textfield_height"
android:background="#drawable/textfeld"
android:inputType="textPassword" />
Actually the first character starts directly on the left border of the edittextfield. Is there an option so that there a bit padding between the first character and the left border of my textbox?
Thanks
You should probably provide padding for all the four edges of the widget by declaring android:padding = 5dp attribute in your EditText.
From what I see in your screen shot, it would be better to use android:layout_margin attribute to provide breathing space between your widgets.
You'll want to set android:padding
But if you plan on using this custom EditText throughout your app, you may want to create a style and store all the custom pieces in there.
So for example in your styles.xml, you'd have:
<style name="Custom.EditText.Style" parent="#android:style/Widget.EditText">
<item name="android:background">#drawable/textfeld</item>
<item name="android:paddingLeft">6dp</item>
<item name="android:paddingTop">4dp</item>
<item name="android:paddingBottom">4dp</item>
</style>
Then in your xml layout, all you'd need is:
<EditText
...
style="#style/Custom.EditText.Style"
/>