Android程式碼設定屬性
阿新 • • 發佈:2018-11-15
/設定佈局檔案的高度,控制元件為FrameLayout
FrameLayout mFrameLayout = holder.getView(R.id.fl_bill_or_image);
ViewGroup.LayoutParams lp = mFrameLayout.getLayoutParams();
//相當於80dp
lp.height = 115;
mFrameLayout.setLayoutParams(lp);
//獲取WRAP_CONTENT屬性
LinearLayout.LayoutParams.WRAP_CONTENT
可見:
view.setVisibility(View.VISIBLE);
//設定背景色,控制元件例子TextVIew
holder.setBackgroundColor(R.id.tv_line, ContextCompat.getColor(getContext(), R.color.lightblue));
//設定Background
ImageView productImage = holder.getView(R.id.iv_product_image);
productImage.setBackground(ContextCompat.getDrawable(getContext(),R.drawable.iv_fillet));
//清除圖片資源,控制元件例子ImageView
productImage.setImageBitmap(null);
//設定圖片不顯示
productImage.setVisibility(View.GONE);
在程式碼裡利用Strings的字串 :
BaseApplication.getContext().getString(R.string.dialog_message)