Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing custom Edittext style in android

I am creating custom edit text in android by adding xml in drawable res.it is as following

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <!-- Border -->
    <item>
        <shape>
            <solid android:color="@color/gray"></solid>
        </shape>
    </item>
    <!-- Body -->
    <item 
          android:bottom="1dp"
          android:right="0dp"
          android:left="0dp"
          android:top="0dp">
        <shape>
            <solid android:color="@color/white"></solid>
        </shape> 
    </item>
</layer-list>


 <EditText
                android:id="@+id/edt_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:background="@drawable/edittext"
                android:digits="1234567890"
                android:ellipsize="end"
                android:focusableInTouchMode="true"
                android:inputType="numberPassword"
                android:singleLine="true"
                android:textColor="@color/dark" />

so i just want edittext as a single line. But when i implement this, for few seconds the upper border of edittext is visible and then it goes away... I am really not getting why this is happening...

like image 784
Meghana M Avatar asked May 12 '15 04:05

Meghana M


People also ask

What is Imeoption android?

android:imeOptions="actionSend" /> You can then listen for presses on the action button by defining a TextView.OnEditorActionListener for the EditText element. In your listener, respond to the appropriate IME action ID defined in the EditorInfo class, such as IME_ACTION_SEND . For example: findViewById<EditText>(R.

What is AppCompatEditText?

AppCompatEditText widget enhanced with emoji capability by using EmojiEditTextHelper . A EditText which supports compatible features on older versions of the platform, including: Allows dynamic tint of its background via the background tint methods in androidx.


1 Answers

Create res/drawable/custom_edittext_style.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true" android:drawable="@drawable/apptheme_textfield_default_holo_light" />
<item android:state_window_focused="false" android:state_enabled="false" android:drawable="@drawable/apptheme_textfield_disabled_holo_light" />
<item android:state_enabled="true" android:state_focused="true" android:drawable="@drawable/apptheme_textfield_activated_holo_light" />
<item android:state_enabled="true" android:state_activated="true" android:drawable="@drawable/apptheme_textfield_focused_holo_light" />
<item android:state_enabled="true" android:drawable="@drawable/apptheme_textfield_default_holo_light" />
<item android:state_focused="true" android:drawable="@drawable/apptheme_textfield_disabled_focused_holo_light" />
<item android:drawable="@drawable/apptheme_textfield_disabled_holo_light" />

And add all require drawable file into drawable folder.

 <EditText
            android:id="@+id/edt_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="@drawable/custom_edittext_style"
            android:digits="1234567890"
            android:ellipsize="end"
            android:focusableInTouchMode="true"
            android:inputType="numberPassword"
            android:singleLine="true"
            android:textColor="@color/dark" />
like image 94
Patel Hiren Avatar answered Oct 27 '22 11:10

Patel Hiren