Ich habe die Floating Action Button
backgroundTintList Farbe, die durch den folgenden Code:Floating Action-Knopf Randfarbe ändert sich nicht
fab.setBackgroundTintList(ColorStateList.valueOf(mResources.getColor(R.color.fab_color)));
Aber ich am Ende die immer im Anschluss an API 4.4.2:
Alles sieht gut auf API 21 < = aber irgendetwas unter API 21, habe ich dieses Problem für die FAB.
ich programmatisch die FAB wie so erstellen:
FloatingActionButton fab = new FloatingActionButton(this);
CoordinatorLayout.LayoutParams layoutParams = new CoordinatorLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
fab.setLayoutParams(layoutParams);
layoutParams.rightMargin = mResources.getDimensionPixelSize(R.dimen.activity_horizontal_margin);
((CoordinatorLayout) findViewById(R.id.coordinatorLayout)).addView(fab);
CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
p.setAnchorId(R.id.appBarLayout);
p.anchorGravity = Gravity.BOTTOM | Gravity.END;
fab.setLayoutParams(p);
fab.setVisibility(View.VISIBLE);
fab.setBackgroundTintList(ColorStateList.valueOf(mResources.getColor(R.color.fab_color)));
fab.setImageDrawable(getResources().getDrawable(R.drawable.ic_button));
ich zufällig auch von der offiziellen source code für die FloatingActionButton
laufen, und ich sah, dass sie eine borderDrawable hier Instanziierung:
@Override
void setBackgroundDrawable(Drawable originalBackground, ColorStateList backgroundTint,
PorterDuff.Mode backgroundTintMode, int rippleColor, int borderWidth) {
// Now we need to tint the original background with the tint
mShapeDrawable = DrawableCompat.wrap(originalBackground.mutate());
DrawableCompat.setTintList(mShapeDrawable, backgroundTint);
if (backgroundTintMode != null) {
DrawableCompat.setTintMode(mShapeDrawable, backgroundTintMode);
}
final Drawable rippleContent;
if (borderWidth > 0) { // BORDER DRAWABLE RIGHT HERE!!
mBorderDrawable = createBorderDrawable(borderWidth, backgroundTint);
rippleContent = new LayerDrawable(new Drawable[]{mBorderDrawable, mShapeDrawable});
} else {
mBorderDrawable = null;
rippleContent = mShapeDrawable;
}
mRippleDrawable = new RippleDrawable(ColorStateList.valueOf(rippleColor),
rippleContent, null);
mShadowViewDelegate.setBackgroundDrawable(mRippleDrawable);
mShadowViewDelegate.setShadowPadding(0, 0, 0, 0);
}
Ich habe andere Ansichten in der App, die einen bestimmten Farbakzent verwenden müssen, so dass diese Option ein Nein ist, und ist nicht wirklich skalierbar. Dies ist eher eine "nukleare" Option und ich würde das lieber nicht tun. – AndyRoid
Dies ist nicht konstruktiv. – AndyRoid
@AndyRoid überprüfen, sobald ich einen anderen Vorschlag in Antwort hinzugefügt – curiousMind