Новое действие не загружается при нажатии на плавающую панель действий - PullRequest
2 голосов
/ 06 августа 2020

В моем проекте я разместил нижнюю панель навигации с плавающей нижней частью, когда пользователь нажимает эту плавающую кнопку, это приводит к новому действию

Не отображает никаких ошибок, но новое действие не загружается, когда я нажимаю плавающую кнопку

Манифест. xml

<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>

Действие 1:

<?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>

Это действие нужно загрузить, когда Я нажимаю плавающую кнопку

<?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>

Main 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));
            }
        });
    }
}

1 Ответ

2 голосов
/ 09 августа 2020

Я думаю, что проблема bcoz в empty_list. xml, поэтому, пожалуйста, удалите этот файл и скопируйте и вставьте его в свой activity.xml файл (вы включаете empty_list. xml файл в вашем activity_main. xml, но в Mainactivity. java u установите представление содержимого как activity. xml так что надеюсь, что он работает

Также добавьте эти две строки в панель меню навигации xml файл под плавающей панелью действий

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