2017-04-05 213 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

相关问题