下面列出了怎么用android.support.v4.widget.ImageViewCompat的API类实例代码及写法,或者点击链接到github查看源代码。
public static void setImageTintList(
@NonNull ImageView view, @Nullable ColorStateList tintList) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) {
// Work around broken workaround in ImageViewCompat, see https://crbug.com/891609#c3.
if (tintList != null && view.getImageTintMode() == null) {
view.setImageTintMode(PorterDuff.Mode.SRC_IN);
}
}
ImageViewCompat.setImageTintList(view, tintList);
}
public static void setMenuButtonColor(Activity activity, int color) {
ColorStateList stateList = new ColorStateList(new int[][]{new int[]{}}, new int[]{color});
ImageView view = findOverflowMenuView(activity);
if (view != null) {
ImageViewCompat.setImageTintMode(view, MULTIPLY);
ImageViewCompat.setImageTintList(view, stateList);
}
}
public void themeViews( EquinoxViewOptions options, int position )
{
title.setTextColor(SuntimesUtils.colorStateList((position < EquinoxViewAdapter.CENTER_POSITION ? options.disabledColor : options.titleColor), options.disabledColor, options.pressedColor));
ImageViewCompat.setImageTintList(btn_flipperNext, SuntimesUtils.colorStateList(options.titleColor, options.disabledColor, options.pressedColor));
ImageViewCompat.setImageTintList(btn_flipperPrev, SuntimesUtils.colorStateList(options.titleColor, options.disabledColor, options.pressedColor));
note_equinox_vernal.themeViews(options.labelColor, options.seasonColors[0], options.textColor);
note_solstice_summer.themeViews(options.labelColor, options.seasonColors[1], options.textColor);
note_equinox_autumnal.themeViews(options.labelColor, options.seasonColors[2], options.textColor);
note_solstice_winter.themeViews(options.labelColor, options.seasonColors[3], options.textColor);
}
private void themeDrawables()
{
ImageViewCompat.setImageTintList(forwardButton, SuntimesUtils.colorStateList(colorAccent, colorDisabled, colorPressed));
SuntimesUtils.colorizeImageView(forwardButton, colorBackground);
ImageViewCompat.setImageTintList(backButton, SuntimesUtils.colorStateList(colorAccent, colorDisabled, colorPressed));
SuntimesUtils.colorizeImageView(backButton, colorBackground);
}
@SuppressWarnings("ResourceType")
public void themeViews(Context context)
{
if (themeOverride != null)
{
color_pressed = color_warning = themeOverride.getActionColor();
color_normal = themeOverride.getTitleColor();
color_accent = themeOverride.getAccentColor();
dialogTitle.setTextColor(themeOverride.getTitleColor());
utcTime.setTextColor(themeOverride.getTimeColor());
worldmap.themeViews(context, themeOverride);
}
if (seekbar != null) {
seekbar.setTrackColor(color_accent);
seekbar.setTickColor(color_accent, color_accent, color_accent);
seekbar.getThumb().setColorFilter(color_accent, PorterDuff.Mode.SRC_IN);
}
ImageViewCompat.setImageTintList(playButton, SuntimesUtils.colorStateList(color_normal, color_disabled, color_pressed));
ImageViewCompat.setImageTintList(resetButton, SuntimesUtils.colorStateList(color_warning, color_disabled, color_pressed));
ImageViewCompat.setImageTintList(recordButton, SuntimesUtils.colorStateList(color_warning, color_disabled, color_pressed));
ImageViewCompat.setImageTintList(pauseButton, SuntimesUtils.colorStateList(color_accent, color_disabled, color_pressed));
ImageViewCompat.setImageTintList(nextButton, SuntimesUtils.colorStateList(color_normal, color_disabled, color_pressed));
ImageViewCompat.setImageTintList(prevButton, SuntimesUtils.colorStateList(color_normal, color_disabled, color_pressed));
ImageViewCompat.setImageTintList(menuButton, SuntimesUtils.colorStateList(color_normal, color_disabled, color_pressed));
if (speedButton != null) {
speedButton.setTextColor(SuntimesUtils.colorStateList(color_normal, color_disabled, color_pressed));
}
}
private void themeDrawables()
{
ImageViewCompat.setImageTintList(forwardButton, SuntimesUtils.colorStateList(colorAccent, colorDisabled, colorPressed));
SuntimesUtils.colorizeImageView(forwardButton, colorBackground);
ImageViewCompat.setImageTintList(backButton, SuntimesUtils.colorStateList(colorAccent, colorDisabled, colorPressed));
SuntimesUtils.colorizeImageView(backButton, colorBackground);
}
protected void themeCardViews(Context context, CardAdapter.CardAdapterOptions options)
{
if (options.themeOverride != null) {
themeCardViews(context, options.themeOverride, options);
}
ImageViewCompat.setImageTintList(btn_flipperNext, SuntimesUtils.colorStateList(options.color_accent, options.color_disabled, options.color_pressed));
ImageViewCompat.setImageTintList(btn_flipperPrev, SuntimesUtils.colorStateList(options.color_accent, options.color_disabled, options.color_pressed));
}
@Override
protected void setAttr(final ImageView view, final int color) {
ImageViewCompat.setImageTintList(view, ColorStateList.valueOf(color));
}
public T imageTintList(ColorStateList tint) {
ImageViewCompat.setImageTintList(view, tint);
return self();
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
final RuuviTag tag = getItem(position);
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.row_item_main, parent, false);
}
TextView txtId = convertView.findViewById(R.id.id);
TextView lastseen = convertView.findViewById(R.id.lastseen);
TextView temp = convertView.findViewById(R.id.row_main_temperature);
TextView humid = convertView.findViewById(R.id.row_main_humidity);
TextView pres = convertView.findViewById(R.id.row_main_pressure);
TextView signal = convertView.findViewById(R.id.row_main_signal);
txtId.setText(tag.getDispayName());
int ballColorRes = (position % 2 == 0) ? R.color.main : R.color.mainLight;
((ImageView)convertView.findViewById(R.id.row_main_letter))
.setImageBitmap(Utils.createBall((int)getContext().getResources().getDimension(R.dimen.letter_ball_radius),
getContext().getResources().getColor(ballColorRes),
Color.WHITE,
txtId.getText().charAt(0) + ""));
convertView.findViewById(R.id.row_main_root).setTag(tag);
//convertView.findViewById(R.id.row_main_letter).setOnClickListener(tagMenuClickListener);
String updatedAt = getContext().getResources().getString(R.string.updated) + " " + Utils.strDescribingTimeSince(tag.updateAt);
lastseen.setText(updatedAt);
AppCompatImageView bell = convertView.findViewById(R.id.bell);
int status = AlarmChecker.getStatus(tag);
switch (status) {
case -1:
bell.setVisibility(View.VISIBLE);
bell.setImageResource(R.drawable.ic_notifications_off_24px);
break;
case 0:
bell.setVisibility(View.VISIBLE);
bell.setImageResource(R.drawable.ic_notifications_on_24px);
break;
case 1:
bell.setImageResource(R.drawable.ic_notifications_active_24px);
bell.setVisibility(bell.getVisibility() == View.VISIBLE ? View.INVISIBLE : View.VISIBLE);
break;
}
ImageViewCompat.setImageTintList(bell, ColorStateList.valueOf(getContext().getResources().getColor(R.color.main)));
temp.setText(tag.getTemperatureString(getContext()));
humid.setText(String.format(getContext().getString(R.string.humidity_reading), tag.humidity));
pres.setText(String.format(getContext().getString(R.string.pressure_reading), tag.pressure));
signal.setText(String.format(getContext().getString(R.string.signal_reading), tag.rssi));
return convertView;
}