How to disable highlight when writing on EditText? - android

I'm trying to change the color or disable the highlight of the text when writing on my EditText.
How can I do that?
How can I set rounded borders to the highlight?
I want to do that becouse, when I start writing on my EditText the highlight overlap the rounded corners of my EditText, and it looks bad.
Code for background color and corner rounded of my EditText:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="5dp" />
<solid android:color="#FFFFFF"/>
</shape>
Code of my edittext:
<EditText
android:id="#+id/editTextUsuario"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/propertieseditextlogin"
android:ems="10" >
<requestFocus />
</EditText>
There are 2 examples of my problem:
Image - Gray highlight
Image - Overlap rounded corners

Try adding this attribute to your editText to disable highlighting.
android:defaultFocusHighlightEnabled="false"
You can create highlight with rounded corners programmatically by creating custom View extending edit text, but that's really lot of work.
Also have a look for material design, with this library you can implement edit text with rounded corners pretty easily.

To disable the highlight of the edittext, you can just write following.
android:background="#00000000"

Give the editext a padding using android:padding or set the background attribute to white

Solution of your second problem
Give padding to your EditText
Example:-
<EditText
android:id="#+id/editTextUsuario"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/propertieseditextlogin"
android:paddingLeft="6dp"
android:ems="10" >
<requestFocus />
</EditText>

Related

How to make the space from the text of the button to its bottom edge independent of the length of the text? (Android)

There are buttons that use the custom style. The distance from the text of the button to its bottom edge differs depending on the length of the text - in case the text is transferred to the second and more lines, the distance to the edge is significantly reduced. Is there a way to somehow make these distances the same? Both buttons are in the LinearLayout. Also i use Calligraphy lib to set custom fonts.
This picture describes the problem.
Buttons in Layout:
<Button
android:id="#+id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/btn_in_text"
android:textAllCaps="false"
android:text="short text"
android:gravity="left|center_vertical"
style="?android:attr/borderlessButtonStyle"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
/>
<Button
android:id="#+id/btn2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/borderlessButtonStyle"
android:background="#drawable/btn_in_text"
android:textAllCaps="false"
android:text="Very long text. The longes text that you saw before"
android:gravity="left|center_vertical"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
/>
btn_in_text.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
<item android:bottom="2dp">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
Tried to use
android:includeFontPadding="false"
android:paddingBottom="2dp"
and
android:lineSpacingMultiplier="1.2"
but it did not help.
The very short answer: add this attribute to both of your <Button> tags:
android:minHeight="0dp"
Because you're using <Buttton> instead of <TextView>, you are getting all of the default styles applied to Buttons by the android framework. One of these is a minimum height. That minimum height, combined with your gravity attribute including center_vertical, means that your text will float in the middle of the button until your text is long enough that it wraps enough times to exceed the button's default height.
Another possible solution is to use <TextView> tags instead of Buttons, and remove the style="?android:attr/borderlessButtonStyle" attribute. This will also let you remove android:textAllCaps="false".
Iam not sure about the specifics of your problem but I had a similar problem where my textsize was changing the button's size as well and fixed it using
android:baselineAligned="false"
In the layout which carries the Buttons since by default the bottom edge of all the text in a row is at the same height.
Here is the link of my solved problem which includes a picture similar to yours :-
In XML Button size changes with its Font size
If that doesn't work try making a fixed button height instead of wrap_content.

Align TextView and EditText left in vertically oriented LinearLayout

I am using a LinearLayout as view group which holds two children (TextView and EditText). My XML code looks as follows:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text View"
android:textSize="20sp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Edit Text"
android:textSize="20sp" />
</LinearLayout>
which will produce the following design:
As depicted in the zoomed-in view on the left, TextViewand EditText are not equally aligned vertically (EditText is indented a bit more as shown by the small red arrows).
It seems there is a bit of a padding (a few dp) around the hint and the line underneath which prevents them from "touching" the left edge of their view field. Is there any way to force the hint within EditText to squeeze to the left of its view field?
How can I get rid of this indentation, other than by adding paddings and margins?
Thanks for any ideas and advice!
Without add any paddings and margins you can use a custom drawable for the background of your Edittext to remove the default padding
in drawable/edittext_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#android:color/transparent" />
</shape>
</item>
<item
android:top="-2dp"
android:right="-2dp"
android:left="-2dp">
<shape>
<solid android:color="#android:color/transparent" />
<stroke
android:width="1dp"
android:color="#000000" />
</shape>
</item>
</layer-list>
Now use it in your editext:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/edittext_bg"
android:hint="Edit Text"
android:textSize="20sp" />
Output:
It should not be in this way... You should check your style.xml, maybe you set additional margins there.
Also, try to specify layout_gravity:"left" attribute.
try typing letters on Edit Text then you can see both textview and edit text was aligned equally
Did you try Constraint layout? It's removing the need to have so much hierarchy in xml layouts and is easy to use.
this preview, run the simulator for correct preview.
But, for best result use https://developer.android.com/reference/android/support/design/widget/TextInputLayout.html

Android ExpandableListView disable group click effect

When I'm clicking on the item the default selectable style is orange background.
I don't want this effect on group header click.
android:listSelector="#android:color/transparent" it's not a good idea because it will effect also on the sub-items.
There's any way to do it without changing the default ExpandableListView style?
Instead of setting a color to the selector set a background shape such as custom_shape.xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#android:color/transparent" />
... and in your xml it would be:
<ExpandableListView
android:layout_width="match_parent"
android:listSelector="#drawable/custom_shape"
android:layout_height="wrap_content"/>
Set only transparent color in listSelector....Working fine
<ExpandableListView
android:layout_width="match_parent"
android:listSelector="#android:color/transparent"
android:layout_height="wrap_content"/>

Is it possible to change the size of icon inside EditText

I am creating a login window with username and password fields and in each I would like to put icons. When I add icon to EditText field I cannot change the size of icon.
Icon is inside EditText field because I want to change EditText background when it is focused.
I tried to put icon and EditText view inside LinearLayout, but I couldn't change layout background when EditText is focused.
My EditText code:
<EditText
android:id="#+id/user_name_edit_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="35dp"
android:layout_marginRight="35dp"
android:layout_marginTop="35dp"
android:background="#drawable/custom_border_selector"
android:drawablePadding="5dp"
android:hint="#string/username"
android:singleLine="true"
android:textColor="#757575"
android:textSize="15sp"
android:drawableLeft="#drawable/ic_person_grey_24dp"
/>
EditText visual:
In case you'd like to solve the problem in xml, here's sample code where you can manipulate your image size/padding:
<!-- USERNAME INPUT -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/edit_text_selector">
<!-- INPUT -->
<EditText
android:id="#+id/username_input"
android:layout_marginLeft="-10dp"
android:layout_toRightOf="#+id/username_icon"
android:text=""
android:hint="Username"
android:padding="10dp"
android:background=""
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<!-- ICON -->
<ImageView
android:padding="3dp"
android:id="#+id/username_icon"
android:src="#drawable/perm_group_personal_info"
android:layout_width="40dp"
android:layout_height="40dp" />
</RelativeLayout>
And here is how it looks like:
You can change the icon and use a smaller one on focus. This is the method you should use.
public void setCompoundDrawablesWithIntrinsicBounds (
int left, int top, int right, int bottom)
Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text. Use 0 if you do not want a Drawable there. The Drawables' bounds will be set to their intrinsic bounds.
Now to add padding you can use this
public void setCompoundDrawablePadding (int pad)
Sets the size of the padding between the compound drawables and the text.
Related XML Attributes:
android:drawablePadding
More information here and here. There are many other methods you might find interesting.
A better way than setting by java would be by setting It inside a layered drawable as follows.
Layered list drawable is as under :
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
>
<shape>
<solid android:color="#color/bg_row_drop_completed"/>
<size android:width="96dp"
/>
<padding android:top="-15dp"
android:bottom="-15dp"/>
<corners android:topLeftRadius="#dimen/btn_add_bg_radius_purple" android:topRightRadius="#dimen/btn_add_bg_radius_purple"/>
</shape>
</item>
<item
>
<bitmap android:src="#drawable/_ic_arrow_drop_up_normal" android:gravity="center_vertical"
></bitmap>
</item>
</layer-list>
see example image

android potential bug in edittext?

I am not sure if I have a bug inside my head ,or it is inside the android's EditText .
I have a simple EditText .
<EditText
android:id="#+id/name_value"
android:layout_width="0dp"
android:layout_height="#dimen/feedback_form_comment_box"
android:layout_weight="6"
android:background="#drawable/black_border"
android:padding="#dimen/feedback_form_padding" />
When I run this , I see a normal edittext with a shapedrawable (just a black border) on the screen. Perfect.
I need to set the gravity now . Because the cursor starts in the middle of the text area. I want the cursor to be displayed in the start of the edittext. So I set the gravity like this .
<EditText
android:id="#+id/name_value"
android:layout_width="0dp"
android:layout_height="#dimen/feedback_form_comment_box"
android:layout_weight="6"
android:gravity="top|left"
android:background="#drawable/black_border"
android:padding="#dimen/feedback_form_padding" />
Now mysteriously , the bottom border of the edittext goes away .
This is the shape drawable I am using .
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<!-- Solid will define the color of our shape's body -->
<solid android:color="#color/white" />
<!-- Stroke will define the border of our shape-->
<stroke
android:width="1dp"
android:color="#color/black" />
</shape>
What's going on?
bro!
i also come across such a question. It happens on some android pad devices.
After a long test, i find that it was the padding of textview which caused this. Not only the shape drawable but also img background will cause this.
A better way is to set padding for textview manually.
If have time,i will continue to check the source code for what have cause this.

Categories

Resources