进度条显示背景

background of progressbar show

我正在使用蓝牙设备读取 QR 码,每当我检测到 Enter 键运行时,每次发现模拟 "Enter" 的东西都会显示 ProgressBar。我喜欢做的是将深色背景设置为透明,就像发布对话框或其他内容时一样。我还没有找到对进度条执行此操作的方法。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layoutLectorBluetooth"
android:background="@android:color/transparent"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<EditText
    android:id="@+id/lectura"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/background_edittext"
    android:inputType="textFilter|textMultiLine"
    android:cursorVisible="false"
    android:singleLine="true"
    android:lines="1"
    android:scrollHorizontally="true"
    android:layout_marginTop="148dp" />



<ImageView
    android:id="@+id/imageView2"
    android:layout_width="300dp"
    android:layout_height="300dp"
    android:layout_alignParentLeft="true"
    android:src="@drawable/scan_trans" />

<TextView
    android:id="@+id/textoEjemplo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageView2"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="26dp"
    android:text="Escanea el E-ticket para validarlo."
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/txtValidando"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textoEjemplo"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="30dp"
    android:text=""
    android:visibility="gone"
    android:textAppearance="?android:attr/textAppearanceSmall" />

<ProgressBar
    android:id="@+id/loader_prueba"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textoEjemplo"
    android:layout_centerHorizontal="true"
    android:visibility="gone"
    android:indeterminate="true" />

 </RelativeLayout>

onCreate Activity

    lectura = (EditText)findViewById(R.id.lectura);
    lectura.setOnKeyListener(new OnKeyListener() {
    public boolean onKey(View view, int keyCode, KeyEvent keyevent)  {
            //THIS!
    findViewById(R.id.loader_prueba).setVisibility(View.VISIBLE);

例子

编辑

您的方法有两处错误:

  1. @android:color/transparent 属性实际上是完全透明的,因为根本没有颜色。你可能想要的是略微不透明的黑色
  2. 如果您将 android:background 应用于 ProgressBar,它实际上不会覆盖整个 window,您必须添加一个新的 View高度和宽度都设置为 match_parent

编辑:根据您现在发布的完整布局,我将添加以下内容(在 RelativeLayout 内):

<RelativeLayout> <!-- that's the one you already have -->
    <View
        android:id="@+id/background_dim"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:background="#42000000"
        android:visibility="gone" />
</RelativeLayout>

然后你还需要设置这个View在显示ProgressBar时可见:

findViewById(R.id.background_dim).setVisibility(View.VISIBLE);