ColorStateList Android的编程方式 [英] ColorStateList Android Programatically

查看:81
本文介绍了ColorStateList Android的编程方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用编程方式来创建一个ColorStateList这一点 -

I am trying to create a ColorStateList programatically using this -

ColorStateList stateList = new ColorStateList(states, colors); 

但我不知道什么是两个参数。

But i am not sure what are the two parameters .

由于按照文档 -

As per the documentation-

public ColorStateList (int[][] states, int[] colors) 
Added in API level 1
Creates a ColorStateList that returns the specified mapping from states to colors. 

有人可以请解释我如何创建呢?

Can somebody please explain me how to create this ?

What is the meaning of two-dimensional array for states?

任何帮助将是非常美联社preciated。

Any Help will be highly appreciated.

推荐答案

请参阅<一href="http://developer.android.com/reference/android/R.attr.html#state_above_anchor">http://developer.android.com/reference/android/R.attr.html#state_above_anchor为可用状态的列表。

See http://developer.android.com/reference/android/R.attr.html#state_above_anchor for a list of available states.

如果你想设置颜色为残疾人,重点不突出,未选中状态等只是否定状态:

If you want to set colors for disabled, unfocused, unchecked states etc. just negate the states:

int[][] states = new int[][] {
    new int[] { android.R.attr.state_enabled}, // enabled
    new int[] {-android.R.attr.state_enabled}, // disabled
    new int[] {-android.R.attr.state_checked}, // unchecked
    new int[] { android.R.attr.state_pressed}  // pressed
};

int[] colors = new int[] {
    Color.BLACK,
    Color.RED,
    Color.GREEN,
    Color.BLUE
};

ColorStateList myList = new ColorStateList(states, colors);

这篇关于ColorStateList Android的编程方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆