现在的位置: 首页 > 综合 > 正文

Android常用代码

2013年10月16日 ⁄ 综合 ⁄ 共 576字 ⁄ 字号 评论关闭

1.设置背景

1) BitmapDrawable d = activity.getResources().getDrawable(R.drawable.sample_image);
   button.setBackgroundDrawable(d);
2) button.setBackgroundResource(R.drawable.sample_image);
3) setBackgroundColor(Color.parseColor("#00F5F5DC"));//透明度+颜色

2.读取布局xml

getLayoutInflater().inflate(R.layout.labeled_text_edit, parentViewG, false);

参数2表示布局的父容器,参数3是否要添加到父容器。

似乎如果参数3为false的时候,参数2设置成null也无所谓。

fragment一般是在onCreateView中的layout来读取布局的。

3.读取资源

context.getResources().getText(R.string.peer_count);
context.getResources().getDrawable(R.drawable.wheel_val);
context.getResources().getRawResource(R.raw.文件名);

抱歉!评论已关闭.