How to change Android design support library?

I want to change the button border color. border color white, inner color black or transparent

I want my button to look like this:

Here's how it should look

+8
android fab material android-design-library
source share
3 answers

fab.xml in drawable

 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:innerRadius="0dp" android:shape="ring" android:thicknessRatio="2" android:useLevel="false" > <solid android:color="@android:color/transparent" /> <stroke android:width="3dp" android:color="@android:color/white" /> </shape> 

Floating action button in layout

 <android.support.design.widget.FloatingActionButton android:id="@+id/buttton_float" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_action_social_notifications" android:background="@drawable/fab" android:layout_margin="@dimen/fab_margin" android:layout_gravity="bottom|right" app:fabSize="normal" app:backgroundTint="@android:color/white" app:rippleColor="@android:color/black" app:borderWidth="0dp" app:elevation="2dp" app:pressedTranslationZ="12dp"/> 

Note: The custom design of your FAB contradicts the Google Material Design guidelines for the Floating action button.

+5
source share

First create a .xml form resource, call ring.xml on it and put the following into it:

 <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:innerRadiusRatio="1" android:shape="ring" android:thicknessRatio="1" android:useLevel="false"> <solid android:color="#FFF"/> <stroke android:width="5dp" android:color="#000"/> </shape> </item> <item> <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/ic_cast_light"/> </item> </layer-list> 

You will need to play with the thickness and innerRadius attributes to fix this, but it must be done! Also, the source of the bitmap is just a filler, you want to place your image F.

Then, when you declare your factory, refer to your ring as follows:

 android:background="@drawable/ring" 

OR

In your Java code, follow these steps:

 FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setBackgroundResource(R.drawable.ring); 

Hope this helps!

+2
source share

If you want to set the border of the float button, you just do it. First create one XML file

fab_background.xml

 <shape xmlns:android="http://schemas.android.com/apk/res/android" android:innerRadius="0dp" android:shape="ring" android:thicknessRatio="2" android:useLevel="false" > <!--Here if you want to set transparent can set--> <solid android:color="@color/white" /> <!--Here you can set your fab button border color--> <stroke android:width="3dp" android:color="@color/white" /> </shape> 

Then after using like this in your xml layout file.

main_activity.xml

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/rl_content_main" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/black"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:padding="5dp" android:background="@drawable/fab_background"> <android.support.design.widget.FloatingActionButton android:id="@+id/fab_map" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:elevation="0dp" android:src="@android:drawable/ic_media_play" app:fabSize="normal" app:elevation="0dp"/> </LinearLayout> </RelativeLayout> 
+1
source share

All Articles