gpt4 book ai didi

android - 单击 float 操作栏时未加载新 Activity

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

在我的项目中,当用户单击该 float 按钮时,我放置了一个带有 float 底部的底部导航栏,它会导致一个新 Activity
当我单击 float 按钮时,它不显示任何错误但未加载新 Activity
list 文件

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Karth.check">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ListCreate" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>
</application>

</manifest>
导航菜单栏
<?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:elevation="100dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
Activity 一:
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".MainActivity">

<include

layout="@layout/toolbar"
/>

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


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


</RelativeLayout>
当我单击 float 按钮时要加载此 Activity
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background = "@color/transparent" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/l1"
android:orientation="horizontal"
>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/close"
android:src="@drawable/ic_close"
android:layout_marginTop="50dp"
android:layout_marginLeft="100dp"
android:layout_marginStart="100dp"
android:layout_marginRight="15dp"
android:layout_marginEnd="15dp"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:fontFamily="@string/sans_serif_thin"
android:text="@string/new_list"
android:textStyle="bold"
android:textSize="20dp"
/>

<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_check_circle"
android:layout_marginTop="50dp"
android:id="@+id/done"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp"

/>

</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/l2"
android:orientation="horizontal"
android:layout_below="@+id/l1"
android:layout_marginTop="20dp"

>
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/img"
android:src="@drawable/ic_image"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listname"
android:hint="@string/enter_the_list_name"
android:layout_marginEnd="50dp"
android:layout_marginRight="50dp"
android:layout_marginTop="60dp"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp"
/>

</LinearLayout>

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/r1"
android:layout_below="@+id/l2"
>
<ScrollView
android:layout_width="409dp"
android:layout_height="612dp"
android:id="@+id/scrol"
android:layout_marginTop="8dp"
>

<LinearLayout
android:id="@+id/l3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"

/>
</ScrollView>
</RelativeLayout>

</RelativeLayout>
主要 Activity
public class MainActivity extends AppCompatActivity {

Toolbar mToolbar;


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

mToolbar=findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.floatingActionButton);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(MainActivity.this, NewListCreate.class));
}
});
}
}

最佳答案

我认为 的问题 bcoz empty_list.xml 所以请删除 该文件并将其复制并粘贴到您的 activity.xml文件(你在你的 activity_main.xml 中包含 empty_list.xml 文件,但在 Mainactivity.java 中你将内容 View 设置为 activity.xml 所以希望它有效
同时在 float 操作栏下的导航菜单栏xml文件中添加这两行

android:clickable="true"
android:focusable="true"

关于android - 单击 float 操作栏时未加载新 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63283896/

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