2017-12-15 5 views
-2

에 추가 밑줄을 제거 :내가 정의 배경 당김과 글고이 글고

enter image description here

글고 코드 :

<EditText 
    android:id="@+id/etName" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@{ViewModel.isAllowEdit ? @drawable/profile_et_background_active : @drawable/profile_et_background}" 
    android:inputType="@{ViewModel.isAllowEdit ? InputType.TYPE_CLASS_TEXT : InputType.TYPE_NULL}" 
    android:text="@={ViewModel.name}" 
    android:textColor="@color/main_dark_text_color" /> 

나는 안드로이드 데이터 바인딩 라이브러리와 MVVM 아키텍처를 사용하고 있습니다.

ViewModel의 isAllowEdit이 EditText 배경보다 @ true로 설정된 경우 @ drawable/profile_et_background_active로 설정하십시오.

isAllowEdit false EditText의 배경이 @ drawable/profile_et_background로 설정되어 있습니다.

또한 inputType을 TYPE_NULL로 설정하여 편집 할 수 없으며 inputType을 TYPE_CLASS_TEXT로 설정하여 편집 할 수 있습니다.

<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:left="-2dp" 
     android:right="-2dp" 
     android:top="-2dp"> 
     <shape> 
      <solid android:color="@android:color/transparent" /> 
      <stroke 
       android:width="1dp" 
       android:color="@color/main_elements_line_color" /> 
     </shape> 
    </item> 

</layer-list> 

드로어 블/사진 profile_et_background 코드 @ : profile_et_background_active/당김 코드 @

<item> 
    <shape android:shape="rectangle"> 
     <solid android:color="@android:color/transparent" /> 
    </shape> 
</item> 

편집 글고 추가 허용 및 사용자 시작 텍스트를 입력 할 때 입력 된 단어 아래에 밑줄이 표시됩니다 (이 단어는 오직

enter image description here

내가 글고 치기에 컬러 필터를 추가하여 그 밑줄을 제거하려고 : 현재 입력 된 단어로, 글고 텍스트의 다른 모든 부분에는 밑줄)이 없습니다

et.setColorFilter(getResources().getColor(android.R.color.transparent), PorterDuff.Mode.SRC_IN) 

을하지만 그렇지 않습니다 작업.

어떻게 그 여분의 밑줄을 제거 할 수 있습니까?

이미 @android 추가하려고 한

UPDATE : 컬러/투명, 내가지고있어 오류가 :

"java.lang.Integer의는 캐스트 할 수없는 android.graphics.drawable하기 .Drawable "

변경"@를 {? ViewModel.isAllowEdit @ 드로어 블/사진 profile_et_background_active : 당김 @/profile_et_background} "

에"@ {ViewModel.isAllowEdit @ 드로어 블/사진 profile_et_backgro? und_active : @android : 색상}/투명 "

업데이트 2

추가 InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS 나를 위해 작동하지 않습니다. 그래서 이것은 맞춤법 검사기의 문제가 아닌 것 같습니다.

답변

0

내 이해에 따라.당신의 EDITTEXT

android:background="@android:color/transparent" 

이를 사용하고 사용자가 입력 한 텍스트에 대해 맞춤법 검사기 중지 할 경우 사용자 정의 투명 당김을 가지고

android:inputType="textNoSuggestions" 
+1

OP는 위젯의 밑줄을 삭제하지 말았지만 텍스트 아래에 나타나는 것을 삭제하지 않았습니다. –

+0

이미 이것을 시도하고 "@ {ViewModel.isAllowEdit? @ drawable/profile_et_background_active : @ drawable/profile_et_background}"을 변경할 때 "java.lang.Integer를 android.graphics.drawable.Drawable에 캐스팅 할 수 없습니다"오류가 발생합니다. "@ {ViewModel.isAllowEdit? @ drawable/profile_et_background_active : @android : color/transparent}" –

+0

@VladMorzhanov 내가 맞으면 맞춤법 검사기로 밑줄을 긋고 있습니까? –

0

을 당신은 글고 치기를 설정할 수 있습니다 사용하거나

를 사용
android:background="@android:color/transparent". 
0

Edittext backgroundTint 값을 특정 색으로 설정할 수 있습니다. 투명한 색을 설정하면 밑줄이 사라집니다.

android:backgroundTint="@android:color/transparent" 

그러나 이것은 단지 API 레벨 21에 사용 또는 XML 높은

아래 21

editText.getBackground().clearColorFilter(); 
0

사용 inputType textNoSuggestions.

<EditText 
    android:id="@+id/text" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:inputType="text|textNoSuggestions"/> 

InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS is equivalent flag for this using code

+0

효과가 있었습니까? – ADM

+0

InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS를 (를) 추가해도 작동하지 않습니다. 그래서 이것은 맞춤법 검사기의 문제가 아닌 것 같습니다. –

+0

맞춤법 검사기 문제입니다. 그 밖의 이유는 무엇입니까 ?? 나는 그것을 테스트했고 내 경우에 효과가 있었다. – ADM

0

나는 위에서 주어진 모든 유효한 답변을 보았다. 하지만 마지막으로 다음과 같이 시도해보십시오.

mEditText.addTextChangedListener(new TextWatcher() { 
      @Override 
      public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { 

      } 

      @Override 
      public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { 

      } 

      @Override 
      public void afterTextChanged(Editable editable) { 
       new Handler().postDelayed(new Runnable() { 
        @Override 
        public void run() { 
         mEditText.clearComposingText(); 
        } 
       },200); 


      } 
     }); 

ClearComposingText 방법이 도움이됩니다. 희망이 도움이됩니다.