I want to make FAB Button in triangular shape, But usually FAB is in circle shape. How will I achieve it.
Try like this:
take triangular shape Drawable and add it
app:backgroundTint should be "null"
I haven't try this yet, but this is my idea. What if you:
make transparent to background color of button using property
background or background-tint
add triangle image using property src
However, we are not suggested to change the shape of the button. Look this: Float Action Button
Related
Currently, I have this back arrow that I'm going to use in my toolbar
What I want is to fill the middle part which a specific color which is the middle part is a transparent part.
currently what i have is this :
Drawable backArrow = getResources().getDrawable(R.drawable.ic_back);
backArrow.setColorFilter(getResources().getColor(R.color.aub_red), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(backArrow);
it only changes the color of the white color part into the red color which is wrong. what I want to fill the transparent part a color not the non - transparent part.
Used this
Drawable backArrow = getResources().getDrawable(R.drawable.ic_back);
backArrow.setColorFilter(getResources().getColor(R.color.colorAccent), PorterDuff.Mode.LIGHTEN);
getSupportActionBar().setHomeAsUpIndicator(backArrow);
for more information click hear
you can use :
DrawableCompat.setTint(yourdrawable,getResources().getColor(R.color.primary));
in java code, or in xml tag :
android:backgroundTint="#color/primary"
I managed to have rounded edge for my button.
I also managed to have a dynamic background color (taken from a webservice).
The problem is when doing this :
btn.setBackgroundResource(R.drawable.radio_button_selector);
btn.setBackgroundColor(Color.parseColor(currentQuestion.backgroundColorButton));
One overrides the other, therefore I cannot have rounded edges AND dynamic background color.
I cannot use a dynamic color in the selector (as it's a static XML).
I cannot set the rounded edges programmatically (the method doesn't exists as far as I know).
How do I do ?
Use this
String backgroundColor= "#fc0000"; // set dynamic color here
btn.setBackgroundColor(Color.parseColor(backgroundColor));
another Examples:
GradientDrawable drawable = new GradientDrawable();
drawable.setShape(GradientDrawable.RECTANGLE);
drawable.setStroke(5, Color.MAGENTA);
drawable.setColor(Color.BLACK);
btnBlackColor.setBackgroundDrawable(drawable);
use this :-
final int color = Color.parseColor(homeCatPOJOS.get(position).getColor());
then implement it in background color :-
btn.setBackgroundResource(R.drawable.radio_button_selector);
btn.setBackgroundColor(color));
I think you are getting color code in String, first convert into int then implement it.
And for round edges make XML file for it and implement it statically.
I have created a button with a Gradient Drawable.
If you look at this button, it has those Extra Grey lines as pointed out by my red arrows. Those don't appear if I create a shape using XML but when i use
Gradient Drawable code seen below it shows these lines. How do I get rid of them??
GradientDrawable gd = new GradientDrawable();
gd.setColor(Color.parseColor("#FFFFFFFF"));
gd.setCornerRadius(20);
gd.setStroke(30, Color.parseColor("#0077CC"));
Button.setBackground(gd);
These become more apparent if i increase the setCorner Radius
Just add style to your button.
style="?android:attr/borderlessButtonStyle"
I'm creating a app with Floating action buttons for social.
and i'm having border on FAB. see:
How to remove this border?
You should just have the black f as a separate drawable, and set that as the source of the FAB. Otherwise, if you want to use the drawable that already has a circular shaped background, don't use a FAB at all, just put it in an ImageButton, with a transparent background:
android:background="#0000"
app:srcCompat="#mipmap/action_fb"
set this peoperty to your FloatingActionButton.
app:borderWidth="0dp"
add this to parent.
xmlns:app="http://schemas.android.com/apk/res-auto"
I want to change Floating Action button shadow colour from black/grey to colorprimary/custom color of shadow ** shadow example like below image with **center blue FAB button with light blue shadow not grey shadow. But we can change the FAB button background color. But as you can see in image there is blue shadow of FAB button.I want to achive that thing.
try this :: app:backgroundTint="#color/colorAccentGrey"
where colorAccentGrey = YourColor
and put xmlns:app="http://schemas.android.com/apk/res-auto" at the beginning of the XML if you forggt,
and for Remove shadow :: app:elevation="0dp"
Hope this will help you.. :)
I think you have 2 options:
as #Uttam said, change the elevation of the FAB widget
to make a custom design and embed it as an image in your layout as shown here http://androidgifts.com/android-material-design-floating-action-button-tutorial/
None of the answer worked for me. So i worked this. anyhow it will give shadow like effect that enough for me
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_add_black"
app:elevation="0dp" // disable outside shawdow
app:borderWidth="30dp" // make borderwidth to 25dp or height of fab
app:backgroundTint="#00E5FF" // now you will see only this color with shawdow
android:backgroundTint="#00E5FF" // since border is 30dp u ll not see this color and if you want to check reduce border width to 25dp then ull see this color in center as a small dot.
/>
A simple solution is to remove the stroke(border-width), the default value is 0.5dp change it to 0dp, that is
app:borderWidth="0dp"
Refer Regular and mini FAB key properties in Material Design documentation!
Link - https://material.io/components/buttons-floating-action-button/android