Переполнение меню отображается на другой панели инструментов

Я подаю заявку, но больше не могу найти проблему. Я запускаю MainActivity с 3-мя элементами в BottomMenuBar, когда при использовании FAB отображается DialogFragment, этот DialogFragment имеет FullScreen и имеет свою собственную панель инструментов. Я не знаю, почему OverflowMenu основного действия отображается в моем DialogFragment, это заставляет мои кнопки не работать, когда я нажимаю. Я должен упомянуть, что кнопки DialogFragment работают без OverflowMenu. Что я могу сделать, чтобы сделать панель инструментов обоих видов независимой? Спасибо, здесь я оставляю код.

Основная деятельность

public class MainActivity extends AppCompatActivity implements BottomNavigationView.OnNavigationItemSelectedListener {


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

        Toolbar myToolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(myToolbar);

        //loading the default fragment
        loadFragment(new TrendsFragment());

        //getting bottom navigation view and attaching the listener
        BottomNavigationView navigation = findViewById(R.id.navigation);
        navigation.setOnNavigationItemSelectedListener(this);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.toolbar_item, menu);

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action_settings_logout:
                FirebaseAuth.getInstance().signOut();
                finish();
                startActivity(new Intent(this, LoginActivity.class));

                break;
        }

        return true;
    }

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        Fragment fragment = null;

        switch (item.getItemId()) {
            case R.id.navigation_trends:
                fragment = new TrendsFragment();
                break;

            case R.id.navigation_my_polls:
                fragment = new MyPollsFragment();
                break;

            case R.id.navigation_friends:
                fragment = new FriendsFragment();
                break;
        }

        return loadFragment(fragment);
    }

    private boolean loadFragment(Fragment fragment) {
        //switching fragment
        if (fragment != null) {
            getFragmentManager()
                    .beginTransaction()
                    .replace(R.id.fragment_container, fragment)
                    .commit();
            return true;
        }
        return false;
    }
}

DialogFragment

public class CreatePollFragment extends DialogFragment {
    private View view;   

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        view = inflater.inflate(R.layout.dialog_new_poll, container, false);

        initViews();
        return view;
    }

    private void initViews(){
        setHasOptionsMenu(true);

        // **** Toolbar
        Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar_1);
        ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);

        ActionBar actionbar = ((AppCompatActivity) getActivity()).getSupportActionBar();
        actionbar.setTitle("New Poll");
        if(actionbar != null){
            actionbar.setDisplayHomeAsUpEnabled(true);
            //actionbar.setHomeButtonEnabled(true);
            actionbar.setHomeAsUpIndicator(R.drawable.ic_close);
        }
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater){
        inflater.inflate(R.menu.save_menu, menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.save) {
            savePoll();
            Toast.makeText(getContext(),"Poll saved", Toast.LENGTH_SHORT).show();
            dismiss();
            return true;
        } else if (id == android.R.id.home) {
            // handle close button click here
            dismiss();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

Панель инструментов MainActivity и DialogFragment

DialogFragment

Основная деятельность

Панель инструментов DialogFragment.xml

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
    </android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>

Панель инструментов MainActivity.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/actionBarSize"
        app:menu="@menu/toolbar_item"/>

</android.support.design.widget.AppBarLayout>

toolbar_item.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

    <item
        android:id="@+id/action_settings_logout"
        android:title="@string/options_toolbar_logout">
    </item>

</menu>

save_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/save"
        app:showAsAction="always|withText"
        android:title="@string/save_action"/>
</menu>

0 ответов

Другие вопросы по тегам