[英]Android Java: How do I prevent my Dialog box from showing MainActivity appname briefly when the Dialog closes?
I'm fairly new to Android development and I've created my first "real" application that does the following:我对 Android 开发还很陌生,我创建了我的第一个“真实”应用程序,它执行以下操作:
MainActivity processes Extra Data and then displays a ViewDialog
that extends Dialog
. MainActivity 处理额外数据,然后显示一个扩展
Dialog
的ViewDialog
。 ViewDialog
has a showDialog()
method that does the following to setup and display the Dialog
: ViewDialog
有一个showDialog()
方法,它执行以下操作来设置和显示Dialog
:
protected void showDialog(final Activity activity) { dialog = new Dialog(activity); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(false); dialog.setContentView(dialog_layout); // Set background color of the dialog ConstraintLayout currentLayout = (ConstraintLayout) dialog.findViewById(R.id.Dialog); // setup of views etc... // Finally dislay `Dialog` dialog.show(); // Method called to start a `DialogTimer` which extends `CountDownTimer` }
MainActivity shows the ViewDialog
as follows: MainActivity 显示
ViewDialog
如下:
public class MainActivity extends AppCompatActivity { private static Context appContext; private static ViewDialog notify; protected void onCreate(Bundle savedInstanceState) { // methods and processing etc... // time to display dialog notify = new ViewDialog(mParameters, mThemeHandler ); // ******************** Show dialog box ******************* notify.showDialog(activity: this); // showDialog just calls `Dialog.show()` notify.ApplyTheme(); }
When the timer expires or the user presses a button the ViewDialog
is closed and the application is finished with the following code:当计时器到期或用户按下按钮时,
ViewDialog
将关闭,应用程序将使用以下代码完成:
mButton1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { CancelTimer(); activity.finishAndRemoveTask(); dialog.dismiss();
The problem is that when the ViewDialog
is dismissed I can occasionally see what looks like a message that is displaying the activities android:label
that is setup in the AndroidManifest file.问题是,当
ViewDialog
被关闭时,我偶尔会看到一条消息,显示在 AndroidManifest 文件中设置的活动android:label
。
Video of what is happening正在发生的事情的视频
I'm not sure why this happens, but I assume it's displaying some item of the MainActivity
layout when the ViewDialog
closes that uses it's own dialog_layout
layout file.我不确定为什么会发生这种情况,但我假设它在
ViewDialog
关闭时显示MainActivity
布局的某些项目,它使用它自己的dialog_layout
布局文件。
I've fiddled with so many different things and changed code/layouts etc and I haven't been able to find my error.我摆弄了很多不同的东西并更改了代码/布局等,但我无法找到我的错误。
What are some pointers and hints that will help me fix this?有哪些指针和提示可以帮助我解决这个问题? I'm happy to provide more details if needed.
如果需要,我很乐意提供更多详细信息。
The layout and manifest files are here:布局和清单文件在这里:
You can achieve this by setting the android:theme attribute to @android:style/Theme.NoTitleBar on your element in your AndroidManifest.xml like this:您可以通过在 AndroidManifest.xml 中的元素上将 android:theme 属性设置为 @android:style/Theme.NoTitleBar 来实现此目的,如下所示:
<activity android:name=".Activity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The code you've posted is not enough to figure out why this is happening, but there is one universal solution not to see Activity title(that is is set in the label field of manifest).您发布的代码不足以弄清楚为什么会发生这种情况,但是有一个通用的解决方案看不到活动标题(即在清单的 label 字段中设置)。
Declare in your styles.xml a new theme like在您的 styles.xml 中声明一个新主题,例如
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowContentOverlay">@null</item>
</style>
and after that make it to be the theme of your activity like this然后让它成为你活动的主题,就像这样
<activity
...
android:name="boha.notify.MainActivity"
android:theme="@style/AppTheme.NoActionBar">
...
</activity>
While I am not 100 percent sure(because this behavior can be altered in an actual code of your activity) I think it might help.虽然我不是 100% 确定(因为这种行为可以在您的活动的实际代码中改变),但我认为它可能会有所帮助。
I hope it will help.我希望它会有所帮助。
notify.setOnDissmissListener({CancelTimer()
activity.finishAndRemoveTask()
dialog.dismiss()})
It turns out that if I change:事实证明,如果我改变:
public class MainActivity extends AppCompatActivity {
to至
public class MainActivity extends Activity {
the problem goes away.问题消失了。 I don't know why, but I'll take it.
我不知道为什么,但我会接受它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.