【发布时间】:2020-06-20 22:39:58
【问题描述】:
我对这张图片中的按钮印象深刻。任何人都可以给我一个关于这个按钮的关键字来研究android?谢谢和最好的问候。 https://i.stack.imgur.com/GYT4K.png
【问题讨论】:
我对这张图片中的按钮印象深刻。任何人都可以给我一个关于这个按钮的关键字来研究android?谢谢和最好的问候。 https://i.stack.imgur.com/GYT4K.png
【问题讨论】:
Try this.
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottom_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:fabAttached="true"
app:backgroundTint="@color/colorPrimary"
app:fabCradleVerticalOffset="12dp">
</com.google.android.material.bottomappbar.BottomAppBar>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:src="@drawable/ic_add_black_24dp"
app:layout_anchor="@+id/bottom_appbar"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.button.MaterialButton
android:id="@+id/toggle_alignment"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_gravity="center"
android:textColor="#fff"
android:text="Toggle FAB alignment"
app:backgroundTint="@color/colorPrimary"/>
</FrameLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
一些注意事项:
不要使用您提供的 BottomAppBar 调用 setSupportActionBar(),因为它会破坏它
由于背景的内部管理,要更改背景颜色,您应该调用 app:backgroundTint 而不是 setBackground
调用 setTitle 或 setSubtitle 将不起作用,因为这些方法被覆盖并为空
【讨论】:
试试这个代码:
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/textTv"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
app:layout_anchor="@id/bottomAppBar"
app:srcCompat="@drawable/ic_add_circle_black_24dp"
android:backgroundTint="#FF0000"
tools:ignore="VectorDrawableCompat" />
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottomAppBar"
style="@style/Widget.MaterialComponents.BottomAppBar.Colored"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:fabAlignmentMode="center"
android:backgroundTint="#4CAF50"
app:navigationIcon="@drawable/ic_open_in_new_white_24dp"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
这将是你的输出:
【讨论】:
我希望这对你有用。
在android中,有一个叫做Floating Action Button的小部件。下面给出了如何写
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:src="@drawable/ic_cart"
android:contentDescription="Add"
app:fabSize="normal"
android:layout_margin="16dp"/>
【讨论】:
您正在查看的按钮是两个小部件的组合。底部应用栏和浮动操作按钮。为此,您必须在底部应用栏上应用 gravity bottom,然后在浮动操作按钮上应用 app:layout_anchor=@id/bottom_bar。根视图应该是 CoordinatorLayout。
【讨论】:
您可以尝试搜索浮动操作按钮 android。(您的是编辑操作按钮。)
在材料设计中引入了很多android中的动作按钮-
您可以尝试下面的材料设计链接作为您的编辑操作按钮。
【讨论】:
我相信您正在寻找的是一个浮动操作按钮。 https://material.io/components/buttons-floating-action-button/# 有很多详细信息。
【讨论】: