2017-04-05 163 views
0

請不要標記這個問題的重複,因爲這件事情只有其中的inputType設置爲手機一個EditText上工作,但它不能在其他的EditText情況下工作,這裏是我的EditText是工作如何在android中啓用editText剪切/複製/粘貼功能?

<EditText 
      android:layout_width="match_parent" 
      android:layout_marginLeft="5dp" 
      android:textColor="@android:color/background_dark" 
      android:padding="@dimen/margin_15" 
      android:textColorHint="@android:color/darker_gray" 

      android:hint="Mobile Number" 
      android:imeOptions="actionNext" 
      android:inputType="phone" 
      android:layout_height="wrap_content" 
      android:background="@null" 
      android:id="@+id/ed_phone"/> 

和其他那一個不是工作

<EditText 
     android:layout_width="match_parent" 
     android:layout_marginLeft="15dp" 
     android:textColor="@android:color/background_dark" 
     android:hint="@string/email" 
     android:inputType="textEmailAddress" 
     android:cursorVisible="true" 
     android:imeOptions="actionNext" 
     android:layout_height="wrap_content" 
     android:textColorHint="@android:color/darker_gray" 
     android:background="@android:color/transparent" 
     android:id="@+id/ed_userName"/> 

這裏是我的應用程序的主題

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">#46C203</item> 
     <item name="windowActionModeOverlay">true</item> 
     <item name="android:windowActionModeOverlay">true</item> 

    </style> 

現在,我已經嘗試了許多方法來解決這個defaul t複製/粘貼功能,沒有找到解決方案,我工作 任何幫助將明顯

+0

你在哪裏顯示editext?在彈出? – rafsanahmad007

+0

沒有在活動佈局 – pkgrover

回答

1

終於得到了我就是用這個方法來隱藏我的鍵盤接觸外面editext解決

@Override 
    public boolean dispatchTouchEvent(MotionEvent event) { 
     View view = getCurrentFocus(); 
     boolean ret = super.dispatchTouchEvent(event); 

     if (view instanceof EditText) { 
      View w = getCurrentFocus(); 
      int scrcoords[] = new int[2]; 
      w.getLocationOnScreen(scrcoords); 
      float x = event.getRawX() + w.getLeft() - scrcoords[0]; 
      float y = event.getRawY() + w.getTop() - scrcoords[1]; 

      if (event.getAction() == MotionEvent.ACTION_UP 
        && (x < w.getLeft() || x >= w.getRight() 
        || y < w.getTop() || y > w.getBottom())) { 

       ((EditText)view).setError(null); 
       view.clearFocus(); 
       InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
       imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0); 
      } 
     } 
     return ret; 
    } 

這裏我只需要註釋此行

view.clearFocus(); 

,現在,它的工作原理

0

您試圖粘貼(從剪貼板)的文本應該是一個有效的電子郵件地址,因爲你指定輸入類型爲電子郵件地址,否則它不會工作。一切順利:)

+0

試過這個,沒有工作 – pkgrover

1

在編輯文本添加此行: -

android:textIsSelectable="true" 

所以你的EditText會是這樣: -

 <EditText 
     android:layout_width="match_parent" 
     android:layout_marginLeft="15dp" 
     android:textColor="@android:color/background_dark" 
     android:hint="mail" 
     android:inputType="textEmailAddress" 
     android:cursorVisible="true" 
     android:imeOptions="actionNext" 
     android:layout_height="wrap_content" 
     android:textColorHint="@android:color/darker_gray" 
     android:background="@android:color/transparent" 
     android:id="@+id/ed_userName" 
     android:textIsSelectable="true"/> 

希望它可以幫助你。 :)

+0

現在我的鍵盤不能打開的類型,它不工作 – pkgrover

+0

@pkgrover在maniefest中更改您的活動標記:

+0

第一次打開鍵盤時,我打開我的活動,但順便說一下,菜單出現的剪切/複製/粘貼出現第一次,但他們不是功能後,我點擊任何他們 – pkgrover

0

你可以嘗試將此屬性添加到您的EditText:

android:textIsSelectable="true" 

希望這有助於。

+0

我的鍵盤不打開打字,它不工作 – pkgrover

相關問題