【问题标题】:Changing translucent background color of progressbar android更改进度条android的半透明背景颜色
【发布时间】: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


【解决方案1】:

刚刚设置 progressBar.setAlpha(0.2f);

【讨论】:

    【解决方案2】:

    你可以用对话框代替progressdialog,

        dialogTransparent = new Dialog(this, android.R.style.Theme_Black);
        View view = LayoutInflater.from(getActivity()).inflate(
                R.layout.remove_border, null);
        dialogTransparent.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialogTransparent.getWindow().setBackgroundDrawableResource(
                R.color.transparent);
        dialogTransparent.setContentView(view);
    

    更新:

       Here the color transparent is  #80FFFFFF
    

    【讨论】:

    • 我厌倦了你的 setbackgrounddrawableresource 代码它只影响进度条的圆形区域并使背景变白。它不影响我标记为红色的背景
    • 会实施并告诉你,但你能告诉我 R.style.theme_black 会影响背景颜色吗?
    • 不,不会产生影响。
    • 问题是进度对话框在扩展片段的类中,因此它在代码中给出“this”错误。
    • 我得到了白色的背景颜色,但不透明度与我在上传的图像中标记为红色的不一样,并且进度动画圆圈出现在屏幕的中心位置。
    【解决方案3】:

    这是十六进制颜色代码的透明颜色比例。
    100% — FF
    95% — F2
    90% — E6
    85% — D9
    80% — 抄送
    75% — 高炉
    70% — B3
    65% — A6
    60% — 99
    55% — 8C
    50% — 80
    45% — 73
    40% — 66
    35% — 59
    30% — 4D
    25% — 40
    20% — 33
    15% — 26
    10% — 1A
    5% — 0D
    0% — 00
    只需在颜色代码前添加不透明度百分比即可。 例如:黑色的颜色代码是#0000。如果我想要具有 50% 透明度的透明黑色意味着只需在 #0000 之前添加 80(即 #800000

    【讨论】:

    • 我不知道从哪里改变颜色。任何属性或示例代码表示赞赏。
    • 只需在 xml 中设置背景颜色。 android:background="#BF0000" 用于 75% 的透明度,而不是 android:background="@android:color/transparent"
    • 我已经为背景颜色设置了@android:color/transparent,因为背景颜色只影响进度条圆形图像,而不影响整个屏幕背景。
    • 手动修复透明度而不是 android:background="@android:color/transparent" 并检查是否有任何运气。
    • 您尝试通过添加 FF 和颜色代码来实现 100% 透明度。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-07
    • 1970-01-01
    • 2012-06-16
    • 2020-01-20
    • 2017-06-02
    • 2019-08-14
    相关资源
    最近更新 更多