我想点击Edittext
时显示我的对话框。但是在我的代码中点击EditText
时,首先选择editText
并显示键盘,然后点击editText
再点击,然后显示我的对话!
我希望点击editText
时不选择edittext
而不显示键盘只显示对话框!
我的xml代码:
<android.support.design.widget.TextInputLayout
android:id="@+id/registerCountryInptLay"
style="@style/registerIptLytStyle"
app:hintAnimationEnabled="true">
<EditText
android:id="@+id/registerCountryEdtTxt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/loginCountry"
android:inputType="text"
android:paddingLeft="@dimen/padding10" />
</android.support.design.widget.TextInputLayout>
我在下面写了editText
点击事件的代码:
@OnClick({R.id.registerCountryEdtTxt, R.id.registerCountryInptLay})
void selectCountry() {
final CountryPicker picker = CountryPicker.newInstance("Select Country"); // dialog title
picker.setListener(new CountryPickerListener() {
@Override
public void onSelectCountry(String name, String code, String dialCode, int flagDrawableResID) {
// Implement your code here
countryName = name;
if (!countryName.isEmpty() && countryName != null) {
countryList.setText(countryName);
}
picker.dismiss();
}
});
picker.show(getSupportFragmentManager(), "COUNTRY_PICKER");
}
我该怎么办?
答案 0 :(得分:0)
只需在EditText中添加以下属性:
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="true"
所以你的代码如下所示:
<EditText
android:id="@+id/registerCountryEdtTxt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/loginCountry"
android:inputType="text"
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="true"
android:paddingLeft="@dimen/padding10" />
</android.support.design.widget.TextInputLayout>
答案 1 :(得分:0)
您可以尝试在OnClick方法中添加它
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
答案 2 :(得分:0)
检查此代码..我认为您正在使用ButterKnife。
registerCountryEdtTxt= (EditText) findViewById(R.id.registerCountryEdtTxt);
registerCountryEdtTxt.setClickable(true);
registerCountryEdtTxt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
void selectCountry()
}
});
void selectCountry() {
final CountryPicker picker = CountryPicker.newInstance("Select Country"); // dialog title
picker.setListener(new CountryPickerListener() {
@Override
public void onSelectCountry(String name, String code, String dialCode, int flagDrawableResID) {
// Implement your code here
countryName = name;
if (!countryName.isEmpty() && countryName != null) {
countryList.setText(countryName);
}
picker.dismiss();
}
});
picker.show(getSupportFragmentManager(), "COUNTRY_PICKER");
}