单击Fragment中的菜单图标搜索导航抽屉

时间:2017-05-02 10:58:17

标签: android navigation-drawer

我在片段中实现了导航抽屉,但它总是在它上面显示一个灰色填充。与Fragment的情况相同,但我通过添加android删除它:fitsSystemWindows =" false"。但是这无法移除导航抽屉上方的填充。我怎么能避免这个?

这是我的片段:

  import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

import com.dummy.R;

public class QueriesActivity extends Fragment {

    Context context;
    DrawerLayout mDrawerLayout;
    boolean mSlideState=false;

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

        View rootView = inflater.inflate(R.layout.activity_queries, container, false);
        return rootView;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {

        super.onViewCreated(view, savedInstanceState);
        context = getActivity();
        mDrawerLayout = (DrawerLayout)view.findViewById(R.id.queries_drawer_layout);
        setHasOptionsMenu(true);
        ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        mDrawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {
            @Override
            public void onDrawerSlide(View view, float v) {

            }

            @Override
            public void onDrawerOpened(View view) {
                mSlideState=true;
            }

            @Override
            public void onDrawerClosed(View view) {
                mSlideState=false;
            }

            @Override
            public void onDrawerStateChanged(int i) {

            }
        });
    }


    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
        menuInflater.inflate(R.menu.menu_filter, menu);
        super.onCreateOptionsMenu(menu, menuInflater);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.search:
                if(mSlideState){
                    mDrawerLayout.closeDrawer(Gravity.END);
                }else{
                    mDrawerLayout.openDrawer(Gravity.END);
                }
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

}

我想在图像中附加实现它。              https://i.stack.imgur.com/BtHKx.png

0 个答案:

没有答案