我如何在android studio中使用图像中的类似代码制作圆形工具栏/动作栏?

问题描述 投票:0回答:2

我正在尝试使用代码而不是背景图片here you can find the example image i'm referring in the question

android android-actionbar navbar
2个回答
0
投票

定义这样的xml文件(这就是我将波顿四舍五入的方式)将xml文件放入可绘制文件夹中

 <?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<corners
    android:radius="25dip" />
<stroke
    android:width="1dp"
    android:color="#000000" />
</shape>

并将xml文件放在background属性中

  <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/dateButton"
            android:background="@drawable/shape"

            ></Button>

也许与工具栏也一样?


0
投票

您可以尝试一下并在工具栏上使用它

GradientDrawable shape =  new GradientDrawable();
shape.setCornerRadius( 8 );
// add some color
// You can add your random color generator here
// and set color
if (i % 2 == 0) {
    shape.setColor(Color.RED);
} else {
    shape.setColor(Color.BLUE);
}

 // now find your view and add background to it
View view = (LinearLayout) findViewById( R.id.my_view );
view.setBackground(shape);

将视图更改为工具栏。

我没写过《守则》,对此我不认为。

© www.soinside.com 2019 - 2024. All rights reserved.