gpt4 book ai didi

android - 自定义进度对话框隐藏软键盘android

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:44:17 24 4
gpt4 key购买 nike

查询说明:我正在使用透明主题的自定义进度对话框。这很好用。我面临的问题是,当我的键盘打开时,如果我显示自定义进度对话框,那么它会强制关闭我的键盘。但是,如果我使用默认的进度对话框,那么它可以正常工作。

Here is Default Progress Dialog :如您所见,即使在出现进度对话框后键盘仍然存在。 我想在自定义进度对话框中实现相同的功能。

Here is Custom Progress Dialog :如您所见,当对话框显示时,键盘会消失。感觉很乏味,每次用户都必须打开键盘。

这是我的代码:

public class CustomProgressDialog extends Dialog {
private ImageView imageView;
private Context mContext;

public CustomProgressDialog(Context context) {
super(context, R.style.DialogTheme);
mContext = context;
getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
WindowManager.LayoutParams wlmp = getWindow().getAttributes();
wlmp.gravity = Gravity.CENTER_HORIZONTAL;
getWindow().setAttributes(wlmp);
setTitle(null);
setCancelable(true);
//setOnCancelListener(null);
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(200, 200);
imageView = new ImageView(context);
imageView.setBackgroundResource(R.drawable.custom_dialog);
layout.addView(imageView, params);
addContentView(layout, params);
}

@Override
public void show() {
super.show();
AnimationDrawable frameAnimation = (AnimationDrawable) imageView.getBackground();
frameAnimation.start();
}

@Override
public void dismiss() {
super.dismiss();
}
}

style.xml 中的对话框主题:

 <style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">@color/actionbar_gradient_endColor</item>
</style>

任何帮助将不胜感激。

<EditText android:id="@+id/et_search_category" 
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/imgClearSearch"
android:background="@drawable/rounded_rdt_txt"
android:hint="Search here..."
android:layout_centerVertical="true"
android:singleLine="true" />

最佳答案

最后,我想出了解决办法:

我看到默认进度对话框扩展了 AlertDialog。但是,在我的代码中,我扩展了 Dialog 类。

现在我正在扩展 ProgressDialog 而不是 Dialog,这很有魅力。

代码如下:

public class MyCustomProgressDialog extends ProgressDialog {
private ImageView imageView;

public MyCustomProgressDialog(Context context) {
super(context, R.style.TransparentProgressDialog);
requestWindowFeature(Window.FEATURE_NO_TITLE);
WindowManager.LayoutParams wlmp = getWindow().getAttributes();
wlmp.gravity = Gravity.CENTER;
getWindow().setAttributes(wlmp);
setTitle(null);
setCancelable(false);
setOnCancelListener(null);

}

public MyCustomProgressDialog(Context context, int theme) {
super(context, theme);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_custom_progress_dialog);

imageView = (ImageView) findViewById(R.id.centerImage);
imageView.setBackgroundResource(R.drawable.custom_dialog);

}

@Override
public void show() {
super.show();
AnimationDrawable frameAnimation = (AnimationDrawable) imageView.getBackground();
frameAnimation.start();
}

@Override
public void dismiss() {
super.dismiss();
}
}

布局文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/centerImage"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerInParent="true"
android:visibility="visible" />
</RelativeLayout>

样式.xml:

<style name="TransparentProgressDialog" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowTitleStyle">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:background">@android:color/transparent</item>
</style>

如何调用?

ProgessDialog mProgressDialog = new MyCustomProgressDialog(this);
mProgressDialog.show(); //to show
mProgressDialog.dismiss(); //to dismiss

关于android - 自定义进度对话框隐藏软键盘android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46743333/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com