code

EditText의 포커스 테두리 제거

codestyles 2020. 9. 20. 10:00
반응형

EditText의 포커스 테두리 제거


EditText View에 초점을 맞출 때 나타나는 테두리를 제거하려면 어떻게해야합니까?

이 뷰는 화면에 공간이 거의 없기 때문에 필요하지만 테두리가 없으면 충분합니다. 에뮬레이터에서 실행하면 주황색 테두리가 나타나고 장치에는 파란색 테두리가 나타납니다.


의 배경을 EditText투명한 색상으로 설정해 보셨습니까 ?

<EditText  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:hint="@string/hello" 
android:background="#00000000"
/>

<EditText
            android:id="@+id/edittext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"  
            android:background="@android:drawable/editbox_background_normal"                 

 />

것이 가능하다. 그러나 사용자가 특정 은유에 익숙하고 일반적인 UX를 변경해서는 안되기 때문에 권장하지 않습니다.

뷰에 다양한 스타일을 적용 할 수 있습니다. 귀하의 경우에는 TextView 요소처럼 보이는 EditText View 요소를 원하는 것처럼 들립니다. 이 경우 View 요소의 상태에 따라 EditText에 다른 배경을 지정해야합니다.

원하는 layout.xml에서 EditText에 배경을 할당합니다.

<EditText  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:hint="@string/hello" android:background="@drawable/custom"
/>

그런 다음 드로어 블 폴더에 custom.xml을 만들고 다음을 추가합니다.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_window_focused="false" android:state_enabled="true"
    android:drawable="@drawable/textfield_default" />
  <item android:state_window_focused="false" android:state_enabled="false"
    android:drawable="@drawable/textfield_disabled" />
  <item android:state_pressed="true" android:drawable="@drawable/textfield_default" />
  <item android:state_enabled="true" android:state_focused="true" android:drawable="@drawable/textfield_default" />
  <item android:state_enabled="true" android:drawable="@drawable/textfield_default" />
  <item android:state_focused="true" android:drawable="@drawable/textfield_disabled" />
  <item android:drawable="@drawable/textfield_disabled" />
</selector>

이것이 EditText View 요소의 가능한 상태입니다. 일반적으로를 사용하여 Android 플랫폼 드로어 블에 직접 액세스 할 수 @android:drawable/textfield_default있지만이 경우 텍스트 필드 드로어 블은 비공개이므로 자신의 드로어 블 폴더에 복사해야합니다. 원본 리소스는의 SDK 설치 폴더에서 찾을 수 있습니다 ANDROID_HOME\platforms\android-(API LEVEL)\data\res\drawable-(*dpi)\.

완료되면 TextView처럼 보이지만 테두리가 완전히없는 EditText로 끝납니다. 에뮬레이터에서 본 주황색 테두리가 기본 Android 드로어 블입니다. 파란색은 공급 업체별로 다릅니다 (삼성 일 수도 있음).

그것이 도움이되었고 그다지 혼동하지 않았기를 바랍니다.


이것이 가장 빠른 솔루션입니다.

<EditText
            android:id="@+id/edittext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"  
            android:background="#00000000"                 

 />

초점에서 EditText 테두리를 제거하기 위해 배경색을 투명하게 유지할 수 있습니다.

방법 1

<EditText 
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#00000000"
/>

참고URL : https://stackoverflow.com/questions/5478109/remove-focus-border-of-edittext

반응형