欢迎光临
我们一直在努力

直播源码网站,自定义平台界面,完成各项内容更改

直播源码网站,自定义平台界面,完成各项内容更改

添加依赖:

implementation 'com.android.support:design:30.0.3'

​使用:

 


    <com.google.android.material.button.MaterialButton
 
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:gravity="center"
        android:insetLeft="50dp"
        android:insetTop="5dp"
        android:insetRight="50dp"
        android:insetBottom="5dp"
        android:text="确认办理"
        android:textColor="#ffffffff"
        app:strokeColor="#000000"
        app:strokeWidth="2dp"
        android:textSize="24sp"
        android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar"
        android:visibility="visible"
        app:backgroundTint="#FFA54C" />

MaterialButton继承AppCompatButton,在原来Button的基础上做了一些扩展,如圆角、描边、前置和后置icon(icon支持设置Size、Tint、Padding、Gravity等),还支持按压水波纹并且设置color,基本能满足日常的需求。

公开属性如下:

 


属性                            描述
app:backgroundTint                  背景着色
app:backgroundTintMode              着色模式
app:strokeColor                     描边颜色
app:strokeWidth                     描边宽度
app:cornerRadius                    圆角大小
app:rippleColor                     按压水波纹颜色
app:icon                            图标icon
app:iconSize                        图标大小
app:iconGravity                     图标重心
app:iconTint                        图标着色
app:iconTintMode                    图标着色模式
app:iconPadding                     图标和文本之间的间距

关于background

在1.2版本以前,MaterialButton只能通过app:backgroundTint属性设置背景色,该属性接收color state list。不能通过android:background设置自定义drawable。

1.2版本后,官方已修复此问题。如果未设置自定义背景,则 MaterialShapeDrawable 仍将用作默认背景。

也就是说,如果按钮背景是纯色,可以通过app:backgroundTint指定;如果按钮背景是渐变色,则需要自己定义drawable,然后通过android:background设置。

注意:如果要使用android:background设置背景,则需要将backgroundTint设置为@empty,否则background不会生效。

 

<com.google.android.material.button.MaterialButton
    android:background=”@drawable/custom_background”
    app:backgroundTint=”@empty” />

指定@empty后,Android Studio会出现红色警告,可以正常运行,忽略就好。不过既然已经自定义drawable,就没必要使用MaterialButton,直接用普通的Button甚至用TextView就好了。

关于阴影:

MD组件默认都是自带阴影的,MaterialButton也不例外。但是有时候我们并不想要按钮有阴影,那么这时候可以指定style为

style="@style/Widget.MaterialComponents.Button.UnelevatedButton",这样就能去掉阴影,让视图看起来扁平化。

关于theme

在MDC1.1.0以后,使用MaterialButton可能会出现闪退的问题,原因就是使用了MD控件,但是未将them设置为MaterialComponents。解决方法可以有几种:

先在style.xml自定义MaterialComponents_Theme

 

 

 <style name="MaterialComponents_Theme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- Customize your theme here. -->
        ...
    </style>

方法一:

AndroidManifest里application节点下配置,作用域为整个应用

 


<application
        ...
        android:theme="@style/MaterialComponents_Theme"

方法二:

只在当前activity配置,作用域为当前activity

 


<activity
        ...
        android:theme="@style/MaterialComponents_Theme"

方法三:

为每个在使用到MD控件的地方配置,作用域只针对当前控件

 


<com.google.android.material.button.MaterialButton
...
    android:theme="@style/Theme.MaterialComponents.Light.NoActionBar" />

以上就是直播源码网站,自定义平台界面,完成各项内容更改, 更多内容欢迎关注之后的文章

 

  • 海报
海报图正在生成中...
赞(0) 打赏
声明:
1、本博客不从事任何主机及服务器租赁业务,不参与任何交易,也绝非中介。博客内容仅记录博主个人感兴趣的服务器测评结果及一些服务器相关的优惠活动,信息均摘自网络或来自服务商主动提供;所以对本博客提及的内容不作直接、间接、法定、约定的保证,博客内容也不具备任何参考价值及引导作用,访问者需自行甄别。
2、访问本博客请务必遵守有关互联网的相关法律、规定与规则;不能利用本博客所提及的内容从事任何违法、违规操作;否则造成的一切后果由访问者自行承担。
3、未成年人及不能独立承担法律责任的个人及群体请勿访问本博客。
4、一旦您访问本博客,即表示您已经知晓并接受了以上声明通告。
文章名称:《直播源码网站,自定义平台界面,完成各项内容更改》
文章链接:https://www.456zj.com/9133.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址