gpt4 book ai didi

安卓 : Floating Action Bar on the Top of Bottom Navigation is Not Working

转载 作者:行者123 更新时间:2023-12-04 09:13:04 24 4
gpt4 key购买 nike

在我的应用程序中,我放置了一个底部导航栏,并添加了带有底部导航栏高度的 float 按钮
我放置了一个 Toast Msg 来检查 float 按钮是否有效但它不起作用
bottom_menu_bar.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"
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="@menu/bottom_nav_menu" />


<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:src="@drawable/ic_add"
android:tint="@color/colorWhite"
app:backgroundTint="@color/colorPrimary"
app:layout_anchor="@id/bottom_nav"
app:elevation="100dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>

</androidx.constraintlayout.widget.ConstraintLayout>
在我的activity_main.xml 中,我包含了一个bottom_menu_bar.xml 文件,并且我在activity_main.xml 中包含了我的Secondactivity.xml 文件
<RelativeLayout

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"
android:layout_alignParentTop="false"
tools:context=".MainActivity">

<include
android:id="@+id/empty_list"
layout="@layout/empty_list" />

<include
android:id="@+id/bottom_nav"
layout="@layout/bottom_menu_bar"
/>
主Activity.Java
public class MainActivity extends AppCompatActivity {



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);



FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.floatingActionButton);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "FloatingPlus Button was Clicked ", Toast.LENGTH_SHORT).show();

}
});
}
}

最佳答案

在您的 fab 按钮中添加这两行

android:clickable="true"
android:focusable="true"
删除 mainactivity.xml 中的 empty_list

关于安卓 : Floating Action Bar on the Top of Bottom Navigation is Not Working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63315587/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com