标签: android-dialog

视图没有附加到窗口管理器(最新解决方案?)

我从我的应用程序中得到了错误报告,所有这些都是一样的.这真的很烦人,因为在我的测试设备(HTC Wildfire,Galaxy S I-II-III,Galaxy Mini,Galaxy Tab 10)中,这个错误从未发生过,对我或我的测试伙伴来说,看起来像用户做了一些与我们不同的事情.

因为这个我不能给你太多有关情况的信息,有一件事我看到,它是一个对话框的解雇,我实际上从来没有通过代码调用.

这是错误:

java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:587)
at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:324)
at android.view.WindowManagerImpl$CompatModeWrapper.removeView(WindowManagerImpl.java:151)
at android.app.Dialog.dismissDialog(Dialog.java:328)
at android.app.Dialog$1.run(Dialog.java:119)
at android.app.Dialog.dismiss(Dialog.java:313)
at android.app.Dialog.cancel(Dialog.java:1113)
at hu.kulcssoft.ingyenkonyv.reader.Reader$JavaScriptInterface$1.run(Reader.java:199)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)

有人能帮助我吗?由于这个问题我每周得到30-40个错误报告,我真的无法弄清楚为什么会这样.

所有建议将不胜感激.谢谢,

android illegalargumentexception android-view android-dialog

8
推荐指数
1
解决办法
1万
查看次数

重新创建Activity后,将再次显示Android Dialog

我有一个Activity,需要在其中显示Dialog.这里一切都很好.我在Activity中覆盖了onCreateDialog方法,这里是代码:

@Override
protected Dialog onCreateDialog(int dialog)
{
    if(dialog == 10)
    {
        if(waitDialog != null)
            waitDialog.dismiss();

        dialogCreated = true;
        waitDialog = CreateWaitDialog(this); 
        return waitDialog;
    }
    else
        return new Dialog(this);
}
Run Code Online (Sandbox Code Playgroud)

其中CreateWaitDialog是创建对话框的自定义方法,而waitDialog是静态变量.

我通过调用showDialog(10)来显示对话框

所有代码都正常运行.

显示对话框后,我正在通过调用关闭它.

if(waitDialog != null)
    waitDialog.hide();
Run Code Online (Sandbox Code Playgroud)

当Activity被销毁时我就会解雇它.

if(dialogCreated)
        dismissDialog(10);
    super.onDestroy();
Run Code Online (Sandbox Code Playgroud)

它正在关闭,一切都很棒.但是,当我更改设备的方向并重新创建活动时,它会自动弹出!我没有打电话给任何showDialog或类似的东西它只是弹出!

android android-dialog android-activity

8
推荐指数
2
解决办法
4813
查看次数

android自定义对话框背景

我需要在Android应用程序中显示自定义对话框.标准AlertDialog设计是不可接受的.Android文档说:

提示:如果需要自定义对话框,则可以将"活动"显示为对话框,而不是使用"对话框API".只需创建一个活动并将其主题设置为清单元素中的Theme.Holo.Dialog:

而已.活动现在显示在对话窗口而不是全屏.

听起来很有希望.我做到了,但透明度不起作用!背景总是灰色的:

在此输入图像描述

这是清单中的一个desc:

<activity
    android:name=".MyDialogActivity"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.Holo.Dialog.NoActionBar" >
</activity>
Run Code Online (Sandbox Code Playgroud)

这是我活动的根源:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="#00000000"
    android:layout_width="400dp"
    android:layout_height="wrap_content" >

    // Content ... //

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我也尝试过android:background="@null"- 效果是一样的.如果我使用android:background="#ff0000"那么它是红色的(应该是).但是我该如何让它变得透明?

更新

我结束了

<style name="MyThemeDialogCustom" parent="android:Theme.Holo.Dialog.NoActionBar" >
    <item name="android:windowBackground">@color/transparent</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
</style>
Run Code Online (Sandbox Code Playgroud)

android android-dialog

8
推荐指数
2
解决办法
1万
查看次数

当使用具有对话框的沉浸模式时,导航.栏重新出现并调整我的布局大小

当我在Android 4.4及更高版本上运行时,我正在我的应用中使用沉浸式模式.(http://developer.android.com/training/system-ui/immersive.html)

我的活动确实以全屏显示,我通过使用按下音量键setOnSystemUiVisibilityChangeListener.我也有类似的代码将对话框放入沉浸式模式.

但是,当显示对话框时,导航.酒吧跳到屏幕上,然后立即撤退.当对话被解雇时,情况更糟 - 导航.酒吧跳跃并调整背后的活动.

以下是我的支持沉浸式模式的课程.它只是在每个Activity的onResume上调用,并且在构建每个对话框时也会调用一个单独的函数.

我错过了任何旗帜或回调,还是已知的Android问题?

public class ImmersiveModeHelper {

    public ImmersiveModeHelper(Activity activity)
    {
        mActivity = activity;
    }

    @SuppressLint("NewApi")
    public void supportFullScreenImmersiveMode()
    {
        MyLog.d("ImmersiveModeHelper: supportFullScreenImmersiveMode: ");

        // Support full-screen immersive mode on Android 4.4 and up
        if (Build.VERSION.SDK_INT >= 19)
        {
            // Get the needed flags by reflection and use them
            try
            {
                final int immersiveFlag = View.class.getField("SYSTEM_UI_FLAG_IMMERSIVE_STICKY")
                        .getInt(null);
                final int hideNavigationFlag = View.class
                        .getField("SYSTEM_UI_FLAG_HIDE_NAVIGATION").getInt(null);
                final int fullScreenFlag = View.class.getField("SYSTEM_UI_FLAG_FULLSCREEN").getInt(
                        null);


                // Set the …
Run Code Online (Sandbox Code Playgroud)

android android-ui android-dialog android-activity android-4.4-kitkat

8
推荐指数
1
解决办法
6155
查看次数

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:

  • Launches MainActivity
  • MainActivity processes Extra Data and then displays a ViewDialog that extends Dialog. ViewDialog has a showDialog() method that does the following to setup and display the 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 ...
    
        // …
    Run Code Online (Sandbox Code Playgroud)

java android android-layout android-dialog

8
推荐指数
1
解决办法
289
查看次数

如何通过DialogFragment使用startActivityForResult()?

我的应用需要添加用户名才能正常运行.mainActivity在顶部显示它从数据库中检索的用户名.mainActivity还有一个按钮,通过startActivityForResult()方法导致'addusername'活动; 当用户实际输入用户名时,只有主活动上的用户名才会刷新并显示."addusername"活动上有一个提交按钮,用于添加用户名,setResult(RESULT_OK);
如果通过单击"addusername"按钮输入用户名,则Everything正常工作.

现在,我在mainActivity中添加了一个对话框,只有在数据库中没有用户名时才会启动应用程序.对话框提供了添加用户名的选项,如果单击该用户名,则会导致"addusername"活动.但按下"提交"按钮后,mainActivity会被调用,但用户名不会刷新(但数据库确实会更新)

以下是"addusername"活动的代码:

public void submitusername(View view) {

    userdatabase name = new userdatabase(this);
    name.open();
    String user = name.getusername();
    name.close();

    EditText cinone = (EditText) findViewById(R.id.username);
    username = cinone.getText().toString();

    if(user.equals("")) {

        userdatabase entry = new userdatabase(Editprofile.this);
        entry.open();
        entry.createEntry(username, null, null, null);
        entry.close();

        Context context = getApplicationContext();
        CharSequence text = "Added new user!";
        int duration = Toast.LENGTH_LONG;

        Toast toast = Toast.makeText(context, text, duration);
        toast.show();

    }

    else {

        userdatabase update = new userdatabase(Editprofile.this);
        update.open();
        update.updateUsername(username);
        update.close();

        Context context = getApplicationContext();
        CharSequence …
Run Code Online (Sandbox Code Playgroud)

java android android-dialog

7
推荐指数
2
解决办法
8477
查看次数

在dialogfragment中删除白色背景

以下是我调用DialogFragment的方法:

DialogSelectAccount myDiag=new DialogSelectAccount();
myDiag.show(ft,"Diag" );
Run Code Online (Sandbox Code Playgroud)

这是(部分)我的DialogFragment的创建方式:

public class DialogSelectAccount extends DialogFragment {
public DialogSelectAccount() {

    }

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRetainInstance(true);
 }

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.dialog_select_account, container, false);
tvMessage = (TextView) rootView.findViewById(R.id.tvMessage);
        btnAccountPublic = (Button) rootView.findViewById(R.id.btnAccountPublic);
        btnAccountEnterprise = (Button) rootView.findViewById(R.id.btnAccountEnterprise);
        tvMessage.setText(message);
        btnAccountPublic.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Login.setAccountType = 2;
                dismiss();
            }
        });
        btnAccountEnterprise.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Login.setAccountType …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-fragments android-dialog android-dialogfragment

7
推荐指数
1
解决办法
7720
查看次数

在 AlertDialog.Builder 中设置文本格式

我无法让 AlertDialog 中的文本以粗体或斜体显示。

我尝试过直接格式化,也尝试过使用Android 字符串资源页面中的 CharSequence 实用程序,但我总是只得到纯文本。
我究竟做错了什么?

MyFragment.java

String idFormatted = String.format(resources.getString(R.string.id));
CharSequence idStyledText = Html.fromHtml(idFormatted);

CharSequence nameItalic = Utilities.italic(resources.getString(R.string.name));

String typeFormatted = String.format(resources.getString(R.string.type));
CharSequence typeStyledText = Html.fromHtml(idFormatted);

AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setPositiveButton("Dismiss",
        new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
            }
        }).setIcon(android.R.drawable.ic_dialog_info);

builder.setMessage( idFormatted + myData.getId() + "\t\t" +  nameItalic + myData.getName() + "\t\t" +  typeFormatted + myData.getType() );   
Dialog dialog = builder.create();
dialog.setTitle("Details");
dialog.show();        
Run Code Online (Sandbox Code Playgroud)

字符串.xml

<string name="id"><i>Id: </i></string>
<string name="name"><i>Name: </i></string> …
Run Code Online (Sandbox Code Playgroud)

android android-dialog

7
推荐指数
1
解决办法
3696
查看次数

浓缩咖啡:断言对话框未显示

如何断言未显示对话框?

目前我有一个测试,检查文本是否不存在于不显示对话框的对话框中

onView(withText("Mobile connection")).inRoot(isDialog()).check(doesNotExist());
Run Code Online (Sandbox Code Playgroud)

但我得到一个 NoMatchingRootException

android.support.test.espresso.NoMatchingRootException: Matcher 'is dialog' did not match any of the following roots: [Root{application-window-token=android.view.ViewRootImpl$W@9acefba, window-token=android.view.ViewRootImpl$W@9acefba, has-window-focus=true, layout-params-type=1, layout-params-string=WM.LayoutParams{(0,0)(fillxfill) ty=1 fl=#81810100 wanim=0x1030465 needsMenuKey=2}, decor-view-string=DecorView{id=-1, visibility=VISIBLE, width=768, height=1280, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=5}}]
at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:1566)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:92)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:56)
at android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:184)
at android.support.test.espresso.ViewInteraction.check(ViewInteraction.java:158)
at uk.co.imagitech.learn2.hp.MainActivityConnectedTest.doesntShowMeteredDialogAtStart(MainActivityConnectedTest.java:43)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:270)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at …
Run Code Online (Sandbox Code Playgroud)

android android-dialog android-testing android-espresso

7
推荐指数
1
解决办法
1611
查看次数

无论我尝试什么,AlertDialog 都不会包装内容

这是我的对话框的 xml 文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/main"
android:paddingTop="23dp"
android:background="@android:color/white">

<ImageView
    android:id="@+id/officer"
    android:layout_width="47dp"
    android:layout_height="47dp"
    android:layout_marginLeft="24dp"
    android:background="@drawable/officerman"/>
<TextView
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Are you sure you want\nto sign out?"
    android:textSize="15.5dp"
    android:textColor="#1C86FF"
    android:layout_marginTop="4dp"
    android:lineSpacingExtra="2dp"
    android:layout_marginLeft="84dp"/>

<LinearLayout
    android:layout_marginTop="20dp"
    android:layout_width="264dp"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="1"
    android:layout_below="@id/officer">

    <Button
        android:id="@+id/yes"
        android:layout_width="wrap_content"
        android:layout_weight="0.5"
        android:layout_height="42dp"
        android:background="#1C86FF"
        android:text="Yes"
        android:textAllCaps="false"
        android:textSize="15dp"
        android:textColor="@android:color/white"/>

    <Button
        android:id="@+id/no"
        android:layout_width="wrap_content"
        android:layout_weight="0.5"
        android:layout_height="42dp"
        android:background="#0078FF"
        android:textSize="15dp"
        android:textColor="@android:color/white"
        android:textAllCaps="false"
        android:text="No"/>

</LinearLayout>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的java代码

    AlertDialog.Builder build = new AlertDialog.Builder(Login.this);
    View lview = getLayoutInflater().inflate(R.layout.dialog_leave,null);
    build.setView(lview);
    AlertDialog dialog = build.create();
    dialog.show(); …
Run Code Online (Sandbox Code Playgroud)

android android-alertdialog android-dialog

7
推荐指数
3
解决办法
6537
查看次数