当用户触摸edittext时,如何显示警告对话框。 我已经尝试过使用onFocusChange()和OnClick()但是没有按预期正常工作,我已经放了一些代码,也很帮助我。
ed2.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus)
{
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
hideSoftKeyboard(btn_set_no);
showAlert();
}
});
}
}
}
})
答案 0 :(得分:1)
嗨,你可以在你的edittext中试试这个, android:focusable =" false" ,然后点击它。检查一下
<EditText
android:id="@+id/ethome_click"
android:layout_width="match_parent"
android:layout_height="@dimen/margin_40"
android:drawableLeft="@drawable/profile_ic"
android:drawablePadding="@dimen/margin_10"
android:hint="@string/search_source"
android:padding="@dimen/margin_5"
android:focusable="false"
android:singleLine="true"
android:textSize="@dimen/text_size_14"
android:theme="@style/Theme.App.Base" />
@BindView(R.id.ethome_click)
EditText ethome_click;
@OnClick({R.id.ethome_click})
public void OnClick(View view) {
switch (view.getId()) {
case R.id.ethome_click:
showAlert();
break;
}
}