1.动态获取View 的id
String imgName = "scenic_image" + (i + 1);
int imgId = res.getIdentifier(imgName, "id", mActivity.getPackageName());
ImageView img = (ImageView) mView.findViewById(imgId);
2.动态修改背景
GradientDrawable background = (GradientDrawable) holder.tv_tag_text.getBackground();
background.setColor(Color.parseColor(entity.getTag_color()));
3.将文本内容放到系统剪贴板里
public voidcopyToClip(String link) {
// 从API11开始android推荐使用android.content.ClipboardManager
ClipboardManager cm = (ClipboardManager)mContext.getSystemService(Context.CLIPBOARD_SERVICE);
// 将文本内容放到系统剪贴板里。
cm.setPrimaryClip(ClipData.newPlainText(null,link));
设置屏幕亮度
WindowManager.LayoutParams params = getWindow().getAttributes();
params.flags|= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
params.screenBrightness=1;
getWindow().setAttributes(params);
4.webView加载富文本 和设置样式
webView.loadDataWithBaseURL(null, entity.getProductDetail(),"text/html","UTF-8",null);
//背景渐变
android:shape="rectangle">
android:angle="270"
android:centerColor="#4CAF50"
android:endColor="#2E7D32"
android:startColor="#81C784"
android:type="linear"/>
Toolbar设置返回
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("底部Tab");
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
toolbar.setNavigationOnClickListener(newView.OnClickListener() {
@Override
public voidonClick(View view) {
onBackPressed();
}
});
网友评论