如何在图像中使用类似代码的Android Studio中的圆形工具栏/操作栏? [英] how can i do a rounded toolbar/actionbar in android studio with code like this in the image?

本文介绍了如何在图像中使用类似代码的Android Studio中的圆形工具栏/操作栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过代码而不是背景图片来实现

I'm trying to do this, with code and not with background image

推荐答案

您可以在材料组件库中使用MaterialToolbar:

You can use the MaterialToolbar in the Material Components Library:

在布局中使用类似以下内容的

In the layout use something like:

<com.google.android.material.appbar.MaterialToolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    style="@style/Widget.MaterialComponents.Toolbar.Primary"
    .../>

然后应用 MaterialShapeDrawable

float radius = getResources().getDimension(R.dimen....);
MaterialShapeDrawable toolbarBackground = (MaterialShapeDrawable) toolbar.getBackground();
toolbarBackground.setShapeAppearanceModel(
    toolbarBackground.getShapeAppearanceModel()
      .toBuilder()
      .setBottomRightCorner(CornerFamily.ROUNDED,radius)
      .setBottomLeftCorner(CornerFamily.ROUNDED,radius)
      .build()
);

这篇关于如何在图像中使用类似代码的Android Studio中的圆形工具栏/操作栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆