继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

关于代码中设置颜色和高度(控件)

白板的微信
关注TA
已关注
手记 341
粉丝 70
获赞 385

1.设置颜色用getResources().getColor();

一定要在构造函数Adapter或者在onCreate();

比如:mGreedColor = context.getResources().getColor(R.color.MainGreed);
public ServeRightAdapter(Context context) {
    this.mContext = context;
    this.mInflater = LayoutInflater.from(context);

    mGreedColor = context.getResources().getColor(R.color.MainGreed);
设值:stateTextView.setTextColor(mRedColor);

2.设置高度用getResources().getDimension();

同理需要初始化

比如:mItemHeight = (int) context.getResources().getDimension(R.dimen.usher_table_item_height); 
在values dimen中 <dimen name="usher_queue_item_height">90dp</dimen>
设置:AbsListView.LayoutParams params = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT,
        mItemHeight);
rowView.setLayoutParams(params);

原文链接:http://www.apkbus.com/blog-455907-59863.html

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP