This is what my floating action button is showing
rather that just showing the actual circle part of the image, it tries to fit the background of my .png file into the floating action button.
here is my xml code:
<android.support.design.widget.FloatingActionButton
android:id="#+id/addToKitchenButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_gravity="bottom|end"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:src="#drawable/fab_icon"
/>
how do I get it to look like this?
I've given my .png file a transparent background already, so I don't know what else I need to do. Please Help.
Thank You.
(Assuming you are using Android Studio) -- Rather than using your own custom .png for the FloatingActionButton's src, create a new vector asset with that icon. Right click your res/drawable folder in Android Studio, and then click to New -> Vector Asset.
The icon you are using is built in to Android Studio, although you could import your own vector asset if you were doing something more custom. The XML it generates will look like this:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
and you can change the color in fillColor. Set your FloatingActionButton to this drawable in android:src and you're good to go.
Try overriding the "design_fab_image_size" in the dimens file
<dimen name="design_fab_image_size" tools:override="true">56dp</dimen>
Also, add
app:tint="#null"
inside your FAB button XML
You dont have to provide the rounded corner image.
I am using and I my xml looks like this
<android.support.design.widget.FloatingActionButton
android:id="#+id/addFolder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="#drawable/plus"
app:layout_anchor="#id/mainRl"
android:background="#ff0000"
app:layout_anchorGravity="bottom|right|end"
android:onClick="onAddFolderClick"
/>
I am using #ff0000(red) as background color, you use the pink you want. It works fine for me.
For a consistent look there are two tings that you need to do. This answer assumes that you really want the look in the link provide by you which is this
First Step - The background color is nothing but your app accent color you need not provide any specific color. So first make sure you have accent color set in your app theme.
Second Step - Once you have done that you need to use the xml code below. You don't even have to create a new png if you want the look in link. You can easily download one in white color add icon from this official google material icons link . You can use this links for most of standard material icons by google.
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_add_white_24dp"/>
Hope this helps. Do let me know if it changed things for you.
EDIT:: If you wish to change the icon color and background to something completely different than your default accent color then you have to use these attributes-
//for custom background
app:backgroundTint="#color/yourCustomColor"
//for custom icon color
android:tint="#color/yourCustomColor"
Related
I'm setting an image to a FloatingActionButton, however the background tint is for some reason overwriting it.
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:background="#drawable/ic_add_circle" />
ic_add_circle is just a simple round image with a cross.
Background tint is automatically set to FFFF4081 also named "colorAccent" in styles and it's shown on top of the image.
My initial ideas was to remove it completely but there's no option to do that. Or just set the tint to be transparent but then it's all white.
Is there a simple way to remove the tint on a FloatingActionButton?
You should use vector drawables in your project.
Click on File, New, Vector Assets and select your preferred vector drawable and OK. This will be added to your drawables folder.
In your FloatingActionButton you can do app:srcCompat="#drawable/ic_add_circle" and don't forget to add vectorDrawables.useSupportLibrary true in gradle default config.
I am trying to change the default FloatingActionButton icon to a add circle icon. I have downloaded the icon ic_add_circle_white_18dp from material.io and added it to the drawable directory inside the andorid project. However when I try to use it inside my activity it displays as a black inner icon as in image
However I want the FAB icon to look like
My FAB icon xml looks like
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#drawable/ic_add_fab"
app:elevation="8dp"
app:backgroundTint="#android:color/holo_blue_light"
app:rippleColor="#android:color/white"/>
I have tried setting the app:backgroundTint value but it doesn't effect the inner icon style
Thanks for any help
Importing Clipart corresponding to the add icon from image asset works:
Steps:
1. Right Click on res.
2. Select New->Image Asset
3. In Icon type, select Action Bar and Tab Icons
4. Provide a name
5. Select ClipArt in Asset type and the click on the Clip Art icon.
6. From the content section select add button
7. In theme set HOLO_DARK
6. Click Next and then finish
In order to use this as an icon, include the following in your XML. Note that to use the icon as source android:src="#drawable/ic_add_fab" is used
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_add_fab" />
Try downloading and using icon with name "add" instead of "add circle"
This worked for me
<android.support.design.widget.FloatingActionButton
android:id="#+id/logout_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/logout"
app:rippleColor="#null"
app:backgroundTint="#null"
app:fabSize="normal"
android:layout_gravity="bottom|center_horizontal"
android:scaleType="center"/>
Also src icon should be the same according to the requirement.
I used 140x140 for xhdpi drawable
Instead of app:srcCompat= use app:src= for images.
Or use fab.setImageResource(R.drawable.ic_add); to programatically set the image.
You need to set scaleType for it to be rendered properly:
android:scaleType="center"
Currently I have a button that looks like this:
What I want to do is to be able to replace the text with this vector drawable but keep the blue rectangle background:
I looked into doing this but I cannot seem to get it right.
I tried the following combination:
<Button
android:id="#+id/deletebutton"
android:layout_width="0dp"
android:layout_height="50dp"
android:src="#drawable/deletebtn24dp"
android:backgroundTint="#color/primaryButtonColor"
android:layout_weight="1"/>
However that just led to a blank blue button with no drawable. What can I do so the drawable replaces the text?
Also I would like to support API levels start at 16+.
You have to use app:srcCompat="#drawable/deletebtn24dp" instead of android:src="#drawable/deletebtn24dp". Using an ImageButton might also be better than using a straight Button.
I am an absolute beginner to Android. I am learning how to design a layout. But I am having problem with ImageView:
When I set the src of ImageView with a PNG file, the dark color background is automatically added to all the images like in screenshot:
The real image of is like this: (There's no background)
This is the xml layout for my toolbar and I did not set any background for the ImageView:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="?attr/colorPrimaryDark">
<ImageButton
android:id="#+id/btn_open_sidebar"
android:src="#drawable/open_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageButton
android:layout_alignParentRight="true"
android:id="#+id/btn_calendar"
android:src="#drawable/calendar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
So how can I make that PNG image transparent or with the same background as the toolbar? I mean, how to remove that default dark background color?
I think because you are using ImageButton android adds a default background to it.
you can add android:backgroud="#android:color/transparent" to your ImageButtons and force android to use transparent background.
It is Default property of ImageButton. This won't happen in ImageView so update your question. Use ImageView or set background of ImageButton to null or a transparent color to fix it
android:background="#android:color/transparent"
If you are using Android Studio, then instead of copy and paste of .png file, right click on drawable and select New -> ImageAsset and then select the image which you want to have in drawable folder. It will remove the dark background part of the image.
Open image in explorer, right click and go to "properties", go to details tab and check the Bit depth. From my experience android studio adds black background if it is not "32". I don't know why it does that but it does not apply transparency otherwise.
I just edit image with "paint.net" and resave it as 32bit.
Its a workaround but works for me everytime.
You have to change you parent layout background color.
This
android:background="?attr/colorPrimaryDark"
to
aandroid:background="any colour code"
You can set the background color of the imageview to "#00000000"
It should do the trick.
The first two hexa-digits in the 8 hexa-digits in a color mark opacity
00 is fully transparent and FF is fully opaque.
In your relative layout you have this background:
android:background="?attr/colorPrimaryDark"
check this color in colors.xlm
Can someone please guide me how exactly can i create a circular buttons and textview in android apps, I am still a new into android development. Please help
You cannot create a real circular view (button or textview) in android - all views are rectangular. That said, you can imitate the look of a circular button by giving it a circular background. There are several ways of doing this. One simple way would be to create a PNG image of a circle, save it in your drawable folder and then set it as a background for your button:
<Button android:background="#drawable/circle_bg" .../>
Another way would be to use custom shapes to draw a circle:
<shape android:shape="oval" ...>
<solid android:color="#FFFFFF"/>
</shape>
Save that as an XML file in your drawable as circle.xml and then reference it in your layout:
<Button android:layout_width="40dp" layout_height="40dp"
android:background="#drawable/circle" ... />
This will create a circular button with 20dp radius.
Of course, you may want to combine this with state selectors to get the highlighted states on touch or focus.
There are loads of examples on the internet. Just search.
As some1 mentioned, to make your custom buttons you've to define Styles:
Custom circle button
About TextView: What do you want to do? Change font? Change colour? Change Size?
You've XML attributes for TextViews if you're doing this by XML. Except to change font, that it was implemented in 4.1.
android:text="TextView"
android:textColor="#288BA2"
android:textSize="30sp"