【问题标题】:Change color of background android using html color reference使用 html 颜色参考更改背景 android 的颜色
【发布时间】:2013-02-02 19:59:27
【问题描述】:

我正在尝试使用 html 颜色参考来更改布局的背景颜色。但我似乎无法让它工作。 这就是我正在尝试的方法

public class FormEngine {

Context context;
RelativeLayout relLayout;

FormEngine(Context ctx) {
    context = ctx;
    relLayout = new RelativeLayout(context);

}

public void clearScreen(int color) {
    relLayout.setBackgroundColor(color);
}

} 这就是我调用这个类的方式

    FormEngine fEngine = new FormEngine(MainActivity.this);
    setContentView(fEngine.relLayout);
    fEngine.clearScreen(0x708090);

现在,如果我只是尝试在 setBackground 颜色中使用 Color.Yellow 它按预期工作,但是当我传递这样的颜色值时,它只显示白色背景。 任何帮助将不胜感激。

【问题讨论】:

    标签: android html layout colors


    【解决方案1】:

    0x708090 是一种完全透明的颜色。试试这个:

    fEngine.clearScreen(0xFF708090);
    

    【讨论】:

    • 非常感谢。我认为 android color 会像在 HTML 中那样工作。
    【解决方案2】:

    Android 颜色使用 ARGB,因此您使用 0x00 作为颜色的 alpha 部分,它是完全透明的。

    使用

    fEngine.clearScreen(0xff708090);
    

    改为。

    更多信息请参见Hex Colors in Android are some times 8 digits. How? What is the difference between #FFFFFF and #FFFFFF00

    【讨论】:

      猜你喜欢
      • 2015-03-02
      • 2012-07-10
      • 1970-01-01
      • 2014-11-08
      • 1970-01-01
      • 2013-09-15
      • 1970-01-01
      • 2013-08-08
      相关资源
      最近更新 更多