android - 进度条显示背景

标签 android bluetooth progress-bar

我正在使用蓝牙设备读取 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);

例子

enter image description here

编辑

enter image description here

最佳答案

您的方法有两个问题:

  1. @android:color/transparent 属性实际上是完全透明的,因为根本没有颜色。您可能想要的是略微不透明的黑色
  2. 如果您将 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/

相关文章:

bluetooth - 如何使用蓝牙发送文件到手机?

java - 在 Android 中配对(绑定(bind))后如何以编程方式连接到蓝牙设备

WPF ProgressBar 不更新

java - 如何从单个 Activity 更新多个 Activity

java - 如何在java中解析BluetoothGattCharacteristic值

android - 延迟暂停、早期恢复和唤醒锁。请解释

R:for循环中的文本进度条

android - Android上的音频合成?

android - 使用蓝牙连接的连续 Android 语音识别

php - 如何制作 jquery css php 进度条(倒计时)?