我正在使用蓝牙设备读取 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>
创建 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);
例子
编辑
最佳答案
您的方法有两个问题:
@android:color/transparent
属性实际上是完全透明的,因为根本没有颜色。您可能想要的是略微不透明的黑色- 如果您将
android:background
应用到ProgressBar
它实际上不会覆盖整个窗口,相反您必须添加一个新的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);
关于android - 进度条显示背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35042900/