【问题标题】:Android: How to get background color of Activity in Java?Android:如何在 Java 中获取 Activity 的背景颜色?
【发布时间】:2010-09-07 07:29:22
【问题描述】:

如何在 Java 中获取 Activity 的背景颜色和文本颜色(子视图的默认颜色)?

【问题讨论】:

    标签: java android android-activity


    【解决方案1】:
    TypedArray array = getTheme().obtainStyledAttributes(new int[] {  
        android.R.attr.colorBackground, 
        android.R.attr.textColorPrimary, 
    }); 
    int backgroundColor = array.getColor(0, 0xFF00FF); 
    int textColor = array.getColor(1, 0xFF00FF); 
    array.recycle();
    

    【讨论】:

    • 非常感谢。
    【解决方案2】:

    背景

    TypedArray array = context.getTheme().obtainStyledAttributes(new int[] {
            android.R.attr.windowBackground});
        int backgroundColor = array.getColor(0, 0xFF00FF);
        array.recycle();
        view.setBackgroundColor(backgroundColor);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-23
      • 2012-04-07
      • 1970-01-01
      • 2011-12-26
      • 2017-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多