Remove underline from TextView which uses Widget.EditText style - android

I have a TextView for showing user's wallet balance in my app. In order to set error indicator on low balance I added Widget.EditText style to the TextView. My issues is after adding this style, the TextView is showing an under line. How can I remove that underline?
My TextView
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/hm_bal"
android:textColor="#color/primary_dark"
android:textSize="14sp"
android:textStyle="bold"
android:layout_gravity="left"
android:padding="3dp"
android:gravity="top"
android:text="----"
style="#android:style/Widget.EditText" />
I don't want to change the style since using this theme was perfect for my requirement except the underline.

Try to set transparent background in your textview
android:background="#android:color/transparent"
LIKE
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/hm_bal"
android:textColor="#color/colorPrimaryDark"
android:textSize="14sp"
android:textStyle="bold"
android:layout_gravity="left"
android:padding="3dp"
android:gravity="top"
android:text="----"
android:background="#android:color/transparent"
style="#android:style/Widget.EditText" />

set background null
android:background="#null"

Related

Android bypassing theme setting

I have a Layout with a TextView in an application - not written by me. I want to set it to bold or change the font family in the xml. In the application written by me it works correctly. But in this one, the change doesn't show. I suppose that's because a theme was applied. If I change the setting programmatically it works and if I set it to bold programmatically it works.
myTextView.Typeface(Typeface.DEFAULT_BOLD).
How can I overwrite the theme setting?
UPDATE:
The Layout that i have is this:
<LinearLayout
android:id="#+id/lFiltro"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10sp"
android:layout_marginEnd="10sp"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:id="#+id/tUno"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="#font/archivo_black"
android:shadowColor="#33b5e5"
android:shadowDx="4"
android:shadowDy="4"
android:shadowRadius="5"
android:text="This is my text"
android:textAlignment="center"
android:textColor="#0000ff"
android:textSize="24sp"
android:textStyle="bold"
android:visibility="visible" />
</LinearLayout>
Try to add
android:textAppearance="#style/TextAppearance.AppCompat.Subhead"
to your TextView xml and change what is after TextAppearance. according to the suggestions you will get.

Style of application changed after upgrading to supportlib:v7

After i upgraded support library from v4 to v7 the syle of Buttons changed.
Even when use an ImageButton and set View.setVisibility(View.Gone) it stills shows the location of it by highlighting like picture below.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="#F44336" >
<TextView
android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="#E53935"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
<ImageButton
android:id="#+id/btnSearch"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="#drawable/find" />
</LinearLayout>
You are seeing "location highlight" because colors of background and textview are different. Background is in this color:
android:background="#F44336"
and linear layout is:
android:background="#E53935"
Those colors are both red and very similar but yet different. Remove background from TextView and "location highlight" will be removed because only layout background color will stay.

Textview width doens't adjust after change content

I'm trying to update the content of a TextView with the data introduced by an EditText. But after change the text, if the original text (hint) was bigger than the new text, the width doens't change.
I have the next string in the Hint Attribute of the TextView, "Please, introduce a amount". If I put 25'5, for example, the textview doesn't resize it width.
First Screen
Second Screen
The Euro symbol is invisible behind the textview, and It's shown after insert some value.
The piece of code for the Amount:
<RelativeLayout
android:id="#+id/rlImporte"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/rel_layout_colors"
android:clickable="true"
android:paddingTop="8dp"
android:paddingBottom="8dp">
<ImageView
android:id="#+id/lst_img3"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="5sp"
android:layout_marginTop="5dp"
android:src="#drawable/icon_importe"/>
<TextView
android:id="#+id/tvImporte"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="false"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/lst_img3"
android:text="#string/IMPORTE_TITLE_STRING"
android:textColor="#android:color/black"
android:textSize="#dimen/title_text_size" />
<TextView
android:id="#+id/tvImporteDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tvImporte"
android:layout_toRightOf="#+id/lst_img3"
android:textColor="#android:color/darker_gray"
android:textSize="#dimen/subtitle_text_size"
android:visibility="visible"
android:hint="#string/IMPORTE_PLACEHOLDER_STRING"
android:textColorHint="#android:color/darker_gray"
android:ellipsize="start"
android:layout_marginRight="4dp" />
<TextView
android:id="#+id/tvEuroSymbol"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tvImporte"
android:layout_toRightOf="#+id/tvImporteDesc"
android:textColor="#android:color/darker_gray"
android:textSize="#dimen/subtitle_text_size"
android:visibility="gone"
android:hint="#string/euro_symbol"
android:textColorHint="#color/blue_quantion"
android:ellipsize="start"
android:paddingLeft="4dp" />
</RelativeLayout>
You seem like you want to change the width of tvImporteDesc dynamically. The short of it is that Android does not allow this, though some people have developed work arounds. (Toggling the visibility that some answers suggest did not work for me). Similar questions:
Change Relative layout width and height dynamically
WRAP_CONTENT not working after dynamically adding views
Since you are trying to fit text on the same line it might be easier to use a single TextView for that line of text, and concatenate the euro symbol?

Space between textview and drawable icon

I'm facing problems with the position of an icon. I've set that icon as drawableLeft of a TextView, this is working fine but, if I set the TextView's gravity to center_horizontal, then a padding space appears between the icon and the text. The code is as follows:
<TextView
style="#style/BaseText.White.Bold"
android:gravity="center_horizontal"
android:drawableStart="#drawable/ic_text"
android:drawableLeft="#drawable/ic_text"
android:text="#string/text"
android:layout_marginBottom="#dimen/margin_small"
android:layout_marginRight="#dimen/margin_big"
android:layout_marginLeft="#dimen/margin_big"
android:padding="0dp"
android:drawablePadding="0dp"/>
What do I have to do to ensure that the icon is shown at the text's left side but horizontally centered?
I've make two screenshots to show you the difference when adding or removing the icon's gravity.
When the textview's gravity is not set, the result is as follows:
But, when the gravity is added, then a padding appears between the text and the icon:
Thanks in advance
Only add android:drawablePadding="10dp" field in your text view refer the coad
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Add New Address"
android:textAppearance="#style/Title"
android:id="#+id/tvAddNewAddress"
android:drawablePadding="20dp"
android:layout_weight="1"
android:padding="5dp"
android:textColor="#color/colorAccent"
android:drawableStart="#android:drawable/arrow_down_float"
/>
Try to give android:gravity="center" to Text View. Also add android:layout_width="wrap_content" and android:layout_height="wrap_content" properties in Text View.
Refer this.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:drawableLeft="#mipmap/ic_launcher"
android:drawablePadding="0dp"
android:drawableStart="#mipmap/ic_launcher"
android:gravity="center"
android:textSize="22sp"
android:padding="0dp"
android:text="TestingTestingTestingTestingTestingTestingTestingTestingTesting" />
</RelativeLayout>
This is what it showing.

How to make TextView in Android wrap and adjust text beautifully?

When text is small then I get this:
But when text is big I get this:
Is it possible that text adjust itself by maybe better using spaces or decreasing little size automatically?
This is my TextView xml:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/seaGreen"
android:gravity="center_vertical"
android:padding="10dp"
android:textColor="#color/white"
android:textSize="35sp" />
For that you need to use external library for that, else you can set gravity as center
Library :
https://github.com/grantland/android-autofittextview
For Text Justify
https://github.com/bluejamesbond/TextJustify-Android
https://github.com/programingjd/justified
OR
you can check this answer
this work for me:
<TextView
android:id="#+id/your_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:textAlignment="center"
android:gravity="center"
android:padding="5dp"
android:text=""
android:textSize="14sp"/>

Categories

Resources