এন্ড্রোইড ফ্লোটিং অ্যাকশন বাটন হলো গোলাকার বাটন। এটা ইউজার ইন্টারফেসের উপরে অবস্থান করে এবং ক্লিক করলে কোন ইভেন্ট সংঘটিত করে। এন্ড্রোইড ফ্লোটিং অ্যাকশন বাটন 3টা সাইজ এ ডিফাইন করা যায় normal এবং mini এবং auto ।
Add Design Support Libray In app Level Gradle.build File . Then Go To Mainactivity.xml file
<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="16dp"
android:src="@android:drawable/ic_dialog_email"/>
Go To MainActivity.java And Add This Line
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// We are showing only toast message. However, you can do anything you need.
Toast.makeText(getApplicationContext(), "You clicked Floating Action Button", Toast.LENGTH_SHORT).show();
}
});
Attributes of Android Floating Action Button Widget
Some of the popular attributes of android Floating Action Button widget are –
| Sr. | XML Attributes | Description |
|---|---|---|
| 1 | app:fabCustomSize | Sets the size of the button in pixels. If set to NO_CUSTOM_SIZE, custom size will not be used and size will be calculated based on the fabSize attribute. |
| 2 | app:fabSize | Sets the size of the button. There are 3 options available – normal, mini and auto. normal is larger than mini. auto will choose size based on the screen size. |
| 3 | app:elevation | Sets elevation of the button. |
| 4 | app:rippleColor | Sets ripple colour for button |
| 5 | app:useCompatPadding | Sets inner padding of button on platform lollipop and after. |