请不要将此问题标记为重复,因为这个东西只能在输入类型设置为电话的一个编辑文本中工作,但它在其他编辑文本情况下不起作用,这是我正在工作的编辑文本
<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>
现在我已经尝试了很多方法来使用这种默认的复制/粘贴功能,但没有找到适合我的解决方案任何帮助都是可观的
在您的编辑文本中添加此行:-
android:textIsSelectable="true"
所以你的编辑文本将是这样的:-
<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"/>
希望它能帮助你。 :)
终于得到了我使用这种方法隐藏键盘以触摸外部 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();
现在它可以工作
您尝试粘贴的文本(从剪贴板(应该是有效的电子邮件地址,因为您将输入类型指定为电子邮件地址,否则它将不起作用。 所有最好的:)
您可以尝试将此属性添加到您的编辑文本中吗:
android:textIsSelectable="true"
希望这有帮助。