如何在Android中使用悬浮按钮

发布时间:2021-05-17 17:16:51 作者:Leah
来源:亿速云 阅读:141

本篇文章为大家展示了如何在Android中使用悬浮按钮,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

步骤1:引用

compile 'com.laocaixw.suspendbuttonlayout:suspendbuttonlayout:1.0.3'

步骤2:xml布局

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout android:layout_height="match_parent" 
 android:layout_width="match_parent" 
 android:orientation="vertical" 
 xmlns:suspend="http://schemas.android.com/apk/res-auto" 
 xmlns:android="http://schemas.android.com/apk/res/android"> 
 
 <com.laocaixw.layout.SuspendButtonLayout 
  android:id="@+id/layout" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" 
  suspend:distance="80dp" 
  suspend:imageSize="50dp" 
  suspend:marginY="100dp" 
  suspend:number="6" 
  suspend:imageMainOpen="@mipmap/suspend_main_open" 
  suspend:imageMainClose="@mipmap/suspend_main_close" 
  suspend:image1="@mipmap/suspend_1" 
  suspend:image2="@mipmap/suspend_2" 
  suspend:image3="@mipmap/suspend_3" 
  suspend:image4="@mipmap/suspend_4" 
  suspend:image5="@mipmap/suspend_5" 
  suspend:image6="@mipmap/suspend_6"> 
 
 </com.laocaixw.layout.SuspendButtonLayout> 
 
</LinearLayout>

以上各属性:

步骤3:Activity使用

public class MainActivity extends AppCompatActivity { 
 
 public String[] suspendChildButtonInfo = {"相机", "音乐", "地图", "亮度", "联系人", "短信"}; 
 
 @Override 
 protected void onCreate(Bundle savedInstanceState) { 
  super.onCreate(savedInstanceState); 
  setContentView(R.layout.activity_suspendbutton); 
 
  final SuspendButtonLayout suspendButtonLayout = (SuspendButtonLayout) findViewById(R.id.layout); 
  suspendButtonLayout.setOnSuspendListener(new SuspendButtonLayout.OnSuspendListener() { 
   @Override 
   public void onButtonStatusChanged(int status) { 
 
   } 
 
   @Override 
   public void onChildButtonClick(int index) { 
    Toast.makeText(MainActivity.this, "您点击了【" 
      + suspendChildButtonInfo[index - 1] + "】按钮!", Toast.LENGTH_SHORT).show(); 
   } 
  }); 
 
/**  

 * suspendButtonLayout.hideSuspendButton(); // 隐藏按钮 
  suspendButtonLayout.showSuspendButton(); // 显示按钮 
 
  suspendButtonLayout.openSuspendButton(); // 展开按钮 
  suspendButtonLayout.closeSuspendButton(); // 关闭按钮 
 
  suspendButtonLayout.setMainCloseImageResource(R.mipmap.suspend_main_close); // 设置关闭时,主按钮的图片 
  suspendButtonLayout.setMainOpenImageResource(R.mipmap.suspend_main_open); // 设置展开时,主按钮的图片 
 
  // 设置按钮位置。isRight:true在右边,false在左边;stayPosY:在'按钮停留区域'从上往下,值为从0到100。 
  suspendButtonLayout.setPosition(isRight, stayPosY); */ 
 
 
 } 
}

Android是什么

Android是一种基于Linux内核的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由美国Google公司和开放手机联盟领导及开发。

上述内容就是如何在Android中使用悬浮按钮,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. 如如何使用journalctl命令?
  2. React中Native悬浮按钮组件怎么用

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

android

上一篇:怎么在springcloud中将consul作为配置中心

下一篇:如何在Spring Boot中使用Activiti

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》