Ask Your Question
0

How can I alter the appearance of an android EditText to switch from a rectangular border to an underscore?

asked 2021-08-24 11:00:00 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-08-21 10:00:00 +0000

qstack gravatar image

You can achieve this by creating a custom shape drawable resource file and setting it as the background of the EditText.

  1. Create a new drawable resource file in your project (ex. custom_edittext.xml)
  2. Paste the following code into the file:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<!-- Remove the default border -->
<solid android:color="@android:color/transparent" />
<stroke android:width="0dp" />

<!-- Add the underline -->
<stroke android:width="2dp"
    android:color="@color/colorAccent" />

</shape>
  1. In your layout XML file, set the background of the EditText to the drawable resource file you just created:
<EditText
    android:id="@+id/myEditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/custom_edittext" />
  1. Adjust the attributes in the shape drawable file to customize the appearance of the underline as desired.
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-08-24 11:00:00 +0000

Seen: 9 times

Last updated: Aug 21 '22