【发布时间】:2021-03-25 11:56:41
【问题描述】:
我正在尝试在 actionBar 上放置一个 floatingActionButton,这可能吗?我该怎么做?
您将在下面找到我当前的 XML:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listframe">
<ImageView
android:id="@+id/arrowTopRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:layout_marginTop="70dp"
android:layout_marginRight="70dp"
android:src="@mipmap/cursor" />
<TextView
android:id="@+id/textNoData"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:layout_marginBottom="240dp"
android:layout_marginRight="80dp"
android:layout_marginLeft="80dp"
android:layout_gravity="center_horizontal"
android:text="@string/empty_list_of_codes" />
<ImageView
android:id="@+id/keyBlurry"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:src="@mipmap/keyblurry"
android:scaleType="center" />
<ImageView
android:id="@+id/LogoDown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginBottom="40dp"
android:layout_marginRight="40dp"
android:src="@mipmap/logoblack" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/buttonAddLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
android:layout_margin="16dp"
app:maxImageSize="56dp"
android:elevation="8dp"
app:srcCompat="@mipmap/addlocation" />
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:id="@+id/list"/>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
在邮件类中,我以编程方式添加我的 actionBar:
actionBar = ((MainActivity)currentActivity).getSupportActionBar();
actionBar.setTitle(R.string.main_title);
我尝试使用我的 floatingButton 的位置,但它最终落在了 actionBar 的后面。任何帮助将不胜感激!
【问题讨论】:
标签: java android android-actionbar floating-action-button