【发布时间】:2014-07-15 04:12:53
【问题描述】:
我想更改具有黑色半透明背景且不透明度小于 50% 的进度条的背景颜色。 我对此进行了很多搜索,但找不到解决方案。 我不知道我是否正确,但这与进度条的 mdecor 属性有关。
以下是我正在使用的代码。
pd = ProgressDialog.show(getActivity(), null, null,true);
pd.setContentView(R.layout.remove_border);
移除边框布局的代码为:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:orientation="vertical" >
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@android:color/transparent"
android:indeterminateDrawable="@drawable/my_progress_indeterminate" />
</LinearLayout>
my_progress_indeterminate 的代码是:
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/loadingiconblack"
android:pivotX="50%"
android:pivotY="50%" />
以下是背景区域用红色圆圈标记的图像。我想将颜色更改为具有相同不透明度的白色。
编辑:
感谢 Sripathi 和 user3298272 将这两种解决方案结合在一起,我的问题的最终解决方案是我的最新答案:
pd = new Dialog(this, android.R.style.Theme_Black);
View view = LayoutInflater.from(this).inflate(R.layout.remove_border, null);
pd.requestWindowFeature(Window.FEATURE_NO_TITLE);
pd.getWindow().setBackgroundDrawableResource(R.color.transparent);
pd.setContentView(view);
pd.show();
remove_border xml 代码: 这里 android:gravity = "center" 是在我的线性布局代码中添加的。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:gravity="center"
android:orientation="vertical" >
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@android:color/transparent"
android:indeterminateDrawable="@drawable/my_progress_indeterminate" />
</LinearLayout>
颜色xml代码:
<resources>
<color name="transparent">#80FFFFFF</color>
</resources>
#80FFFFFF 80 是我从 user3298272 获取的不透明度值 50%。
【问题讨论】:
-
progressDialog.setFeatureDrawableAlpha(featureId, alpha);
-
@Sripathi featureid 的值是多少?
-
您希望设置为背景的可绘制对象的 ID。从文档中, featureId 想要更改的可绘制功能。特征是由 Window 定义的常量。 alpha alpha量,0为完全透明,255为完全不透明。
标签: android android-alertdialog android-progressbar