下面列出了androidx.appcompat.widget.AppCompatTextView#setTextColor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void addParentView(String str) {
AppCompatTextView textView = new AppCompatTextView(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.topMargin = SizeUtil.dp2pxSize(this, 8);
textView.setTextSize(15);
textView.setText(str);
textView.setTextColor(ContextCompat.getColor(this, R.color.colorPrimary));
mInfoParent.addView(textView, params);
}
private void addParent2View(String str) {
AppCompatTextView textView = new AppCompatTextView(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.topMargin = SizeUtil.dp2pxSize(this, 4);
params.setMarginStart(SizeUtil.dp2pxSize(this, 6));
textView.setTextSize(15);
textView.setText(str);
textView.setTextColor(ContextCompat.getColor(this, R.color.blue500));
mInfoParent.addView(textView, params);
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setSupportActionBar(R.id.sl_toolbar);
mVState = findViewById(R.id.sl_lyt_state);
final RadioGroup state = findViewById(R.id.sl_rg_state);
final RadioGroup mode = findViewById(R.id.sl_rg_mode);
mDLoading = ContextCompat.getDrawable(this, R.drawable.ic_statelayout_loading);
mDError = ContextCompat.getDrawable(this, R.drawable.ic_statelayout_error);
mDEmpty = ContextCompat.getDrawable(this, R.drawable.ic_statelayout_empty);
final CircularProgressImageView loading = new CircularProgressImageView(this);
loading.setColorSchemeColors(
ContextCompat.getColor(this, android.R.color.holo_red_light),
ContextCompat.getColor(this, android.R.color.holo_blue_light),
ContextCompat.getColor(this, android.R.color.holo_green_light),
ContextCompat.getColor(this, android.R.color.holo_orange_light),
ContextCompat.getColor(this, android.R.color.holo_purple));
mVLoading = loading;
final AppCompatTextView error = new AppCompatTextView(this);
error.setText(R.string.sl_change_state_error);
error.setTextColor(0xffff4081);
error.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 64);
mVError = error;
final AppCompatTextView empty = new AppCompatTextView(this);
empty.setText(R.string.sl_change_state_empty);
empty.setTextColor(0xff092d6d);
empty.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 64);
mVEmpty = empty;
state.setOnCheckedChangeListener(this);
state.check(R.id.sl_rb_normal);
mode.setOnCheckedChangeListener(this);
mode.check(R.id.sl_rb_drawable);
mVState.setOnClickListener(this);
}
private AppCompatTextView createTextView(Context context) {
final float density = context.getResources().getDisplayMetrics().density;
AppCompatTextView text = new AppCompatTextView(context);
text.setTextColor(0xff999999);
text.setGravity(Gravity.CENTER);
text.setMinimumWidth((int) (64 * density));
text.setMinimumHeight((int) (48 * density));
text.setBackgroundResource(R.drawable.bg_headerfootergridview_item);
return text;
}
ViewHolder(ViewGroup parent) {
super(new AppCompatTextView(parent.getContext()));
mVText = (AppCompatTextView) itemView;
mVText.setGravity(Gravity.CENTER);
mVText.setBackgroundColor(0xff00dd00);
mVText.setTextColor(0xffffffff);
}