自定义Dialog样式 虚拟键盘的隐藏 TextView的图标


@null

true
true

false
@android:color/transparent

true


true


@android:color/transparent
@null
true
true
true
@null
@android:style/Animation.Dialog
true

TextView 设置图标
Drawable img = getResources().getDrawable(R.drawable.left);
img.setBounds(0, 0, img.getMinimumWidth(), img.getMinimumHeight());
tvLeft.setCompoundDrawables(img, null, null, null);

View view = getWindow().peekDecorView();
if (view != null) {
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以为您提供代码示例。请按照以下步骤操作: 1. 在您的 Android 项目中创建一个新的 XML 布局文件,用于自定义 Dialog 的布局。例如,您可以创建一个名为 custom_dialog_layout.xml 的文件,并在其中添加以下代码: ```xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <!-- 第一个 TextView --> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="第一个 TextView" /> <!-- 第二个 TextView --> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="第二个 TextView" /> <!-- 四个 RadioButton --> <RadioGroup android:layout_width="match_parent" android:layout_height="wrap_content"> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="RadioButton 1" android:id="@+id/radio_button_1" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="RadioButton 2" android:id="@+id/radio_button_2" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="RadioButton 3" android:id="@+id/radio_button_3" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="RadioButton 4" android:id="@+id/radio_button_4" /> </RadioGroup> </LinearLayout> ``` 2. 在您的 PreferenceFragment 或 PreferenceActivity 中,为您的 Preference 添加一个 setOnPreferenceClickListener 点击事件。在这个事件中,创建一个自定义 Dialog,并将上面的布局文件作为 Dialog 的视图。例如,您可以添加以下代码: ```java Preference myPreference = findPreference("my_preference_key"); myPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { // 创建自定义 Dialog final Dialog dialog = new Dialog(getActivity()); dialog.setContentView(R.layout.custom_dialog_layout); // 获取四个 RadioButton RadioButton radioButton1 = dialog.findViewById(R.id.radio_button_1); RadioButton radioButton2 = dialog.findViewById(R.id.radio_button_2); RadioButton radioButton3 = dialog.findViewById(R.id.radio_button_3); RadioButton radioButton4 = dialog.findViewById(R.id.radio_button_4); // 为四个 RadioButton 添加点击事件 radioButton1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 当 RadioButton 1 被点击时执行的代码 } }); radioButton2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 当 RadioButton 2 被点击时执行的代码 } }); radioButton3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 当 RadioButton 3 被点击时执行的代码 } }); radioButton4.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 当 RadioButton 4 被点击时执行的代码 } }); // 获取“确定”和“取消”按钮 Button cancelButton = dialog.findViewById(R.id.cancel_button); Button okButton = dialog.findViewById(R.id.ok_button); // 为“确定”和“取消”按钮添加点击事件 cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 当“取消”按钮被点击时执行的代码 dialog.dismiss(); } }); okButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 当“确定”按钮被点击时执行的代码 dialog.dismiss(); } }); // 显示 Dialog dialog.show(); return true; } }); ``` 请注意,这的 my_preference_key 应该替换为您自己的 Preference 的键值。此外,您可以根据需要更改“确定”和“取消”按钮的文本。 这样,您就可以在 Preference 的 setOnPreferenceClickListener 点击事件中创建一个自定义Dialog,其中包含两个 TextView、四个 RadioButton 和“取消”、“确定”按钮,并为每个 RadioButton 添加点击事件了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值