0

我一直在寻找这个问题,但找不到解决方案;

当您创建 ProgressDialog 时,主视图变为灰色并失去焦点,我想要做的是让主视图中的元素保持焦点(比如说 Admob)并在显示 ProgressDialog 时保持它可用

更新:代码!

View mainview = LayoutInflater.from(MainAct).inflate(R.layout.activity_main, null);

        View adView = mainview.findViewById(R.id.adView);
        mProgress = new ProgressDialog(MainAct);
        mProgress.setMessage("Downloading...");
        mProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        mProgress.setCancelable(false);
        mProgress.setCanceledOnTouchOutside(false);
        mProgress.show();
        adView.requestFocus();

似乎使用 reaquestFocus 不起作用,仅适用于表单元素,而不是将元素带到 TOP

更新 2: 样本

4

1 回答 1

0
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/linlaHeaderProgress"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:orientation="horizontal"
            android:visibility="gone" >

            <ProgressBar
                android:id="@+id/pbHeaderProgress"
                style="@style/Spinner"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="2dp" >
            </ProgressBar>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:gravity="left|center"
                android:padding="2dp"
                android:text="Loading...."
                android:textColor="#F1F1F1"
                android:textSize="20sp" >
            </TextView>
        </LinearLayout>

        <ListView
            android:id="@+id/list"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1"
            android:cacheColorHint="@android:color/transparent"
            android:divider="#000000"
            android:dividerHeight="0dp"
            android:fadingEdge="none"
            android:persistentDrawingCache="scrolling" >
        </ListView>

        <TextView
            android:id="@android:id/empty"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:padding="10dp"
            android:textColor="#f1f1f1"
            android:textSize="15sp"
            android:textStyle="bold"
            android:visibility="gone" >
        </TextView>
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom|center"
        android:orientation="horizontal" >

        <com.google.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="MY_AD_UNIT_ID"
            ads:loadAdOnCreate="true"
            ads:testDevices="TEST_EMULATOR, MY_TEST_DEVICE_ID" />
    </LinearLayout>

</LinearLayout>

上面的代码用于几乎专门用于我自己的应用程序的布局。我在加载数据时所做的非常简单。

查看 ProgressBar 在 XML 中是如何定义的。在仍在加载数据的同时,由于设置了属性,我将其更改LinearLayout linlaHeaderProgressVISIBLE有效地隐藏了它下面的内容。ListView加载完数据后,我将 的可见性更改LinearLayout linlaHeaderProgressGONE. 这里需要注意的一点是,位于 XML 底部的 Admob XML 始终对用户可见,并且可以在数据加载/完成加载之前或之后的任何时间进行交互。

如果您需要以 的形式显示此 XML Dialog,您始终可以通过将主题附加到此活动来实现。

希望其中一些对您的努力有所帮助。

更新

检查这些教程。这些是我可以通过快速搜索显示Horizontal ProgressBar. 您正在使用ProgressDialog.

  1. http://www.techrepublic.com/blog/app-builder/androids-batterymanager-and-progressbar-two-for-one-tutorial/703

  2. http://theandroid.in/example-of-progressbar-in-android/

最后,使用此Google 搜索查看一些使活动看起来像对话框的示例。

这应该可以帮助您实现屏幕截图的建议。

于 2013-01-25T10:29:34.317 回答