当前位置: 代码迷 >> 综合 >> Android中代码动态修改控件属性
  详细解决方案

Android中代码动态修改控件属性

热度:67   发布时间:2024-02-19 21:15:16.0

修改字体的粗细

tipTextView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));//加粗tipTextView.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));//常规

设置字体的颜色

leftTextView.setTextColor(context.getResources().getColor(R.color.black_191919));

设置显示隐藏

rightView.setVisibility(View.VISIBLE);

设置LayoutParams(设置间距和宽度)

kotlin写法:

 button.setOnClickListener {val layoutParams = it.layoutParams as ConstraintLayout.LayoutParamslayoutParams.width = DpAndPx.Dp2Px(188f)layoutParams.leftMargin  = DpAndPx.Dp2Px(100f)it.layoutParams = layoutParams}

 

  相关解决方案