Android动作导航抽屉叠加动作栏

时间:2015-06-09 10:44:03

标签: android android-actionbar android-navigation

我在我的应用程序中实现了导航抽屉。我希望这个导航抽屉显示就像谷歌播放,即它将覆盖动作栏。我用谷歌搜索,但没有找到任何完美的解决方案。由于我已经实现了导航抽屉,所以我不想实现覆盖式的android导航抽屉。有什么办法可以将导航抽屉变成叠加的导航抽屉。我试图在我的onDeawerOpen()中将应用程序主题更改为无操作栏,但这对我不起作用。任何机构对此都有任何简单的想法。或者我必须实现覆盖式导航抽屉?这是我MainClass的代码。

public class Activity_Home extends Activity {
    private String[] titles;
    private DrawerLayout drawerLayout;
    private ListView drawerList;
    private ArrayList<Model_Drawer_Items> drawerItems;
    private TypedArray drawerIcons;
    Adpater_DrawerAdapter drawerAdapter;
    private ActionBarDrawerToggle actionBarDrawerToggle;
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.drawer_main);
        setupDrawer();
        ActionBar actionBar = getActionBar();
        actionBar.setHomeButtonEnabled(true);
        actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.back, R.string.app_name, R.string.app_name

        ) {
            public void onDrawerClosed(View view) {

            }

            public void onDrawerOpened(View drawerView) {
            //  setTheme(R.style.noActionBarTheme);

            }
        };
        drawerLayout.setDrawerListener(actionBarDrawerToggle);
        drawerList.setOnItemClickListener(new DrawerItemClickListener());
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.activity__main, menu);

        return super.onCreateOptionsMenu(menu);

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (actionBarDrawerToggle.onOptionsItemSelected(item)) {

        }
        return super.onOptionsItemSelected(item);
        // }
    }

    public void setupDrawer() {
        try {
            drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
            drawerList = (ListView) findViewById(R.id.drawer_list);

            View header = getLayoutInflater().inflate(R.layout.drawer_header, null);
            drawerList.addHeaderView(header);
            drawerIcons = getResources().obtainTypedArray(R.array.navigation_iconos);
            titles = getResources().getStringArray(R.array.nav_options);
            drawerItems = new ArrayList<Model_Drawer_Items>();
            drawerItems.add(new Model_Drawer_Items(titles[0], drawerIcons.getResourceId(0, -1)));
            drawerItems.add(new Model_Drawer_Items(titles[1], drawerIcons.getResourceId(1, -1)));
            drawerItems.add(new Model_Drawer_Items(titles[2], drawerIcons.getResourceId(2, -1)));
            drawerItems.add(new Model_Drawer_Items(titles[3], drawerIcons.getResourceId(3, -1)));
            drawerItems.add(new Model_Drawer_Items(titles[4], drawerIcons.getResourceId(4, -1)));
            drawerItems.add(new Model_Drawer_Items(titles[5], drawerIcons.getResourceId(5, -1)));
            drawerItems.add(new Model_Drawer_Items(titles[6], drawerIcons.getResourceId(6, -1)));
            drawerItems.add(new Model_Drawer_Items(titles[7], drawerIcons.getResourceId(6, -1)));
            drawerItems.add(new Model_Drawer_Items(titles[8], drawerIcons.getResourceId(6, -1)));
            drawerItems.add(new Model_Drawer_Items(titles[9], drawerIcons.getResourceId(6, -1)));
            drawerItems.add(new Model_Drawer_Items(titles[10], drawerIcons.getResourceId(6, -1)));
            drawerAdapter = new Adpater_DrawerAdapter(this, drawerItems);
            drawerList.setAdapter(drawerAdapter);
        } catch (NotFoundException e) {

            e.printStackTrace();
        }
    }

    private class DrawerItemClickListener implements ListView.OnItemClickListener {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectItem(position);
        }

        private void selectItem(int position) {

            switch (position) {
            default:
                break;
            }

        }

    }

}

我的抽屉工作得很好。只想要一个叠加的。谢谢提前。还有一件事。 overlay-ed抽屉是否仅适用于4.0及以上版本?

0 个答案:

没有答案