看不到ActionBar切换按钮

时间:2015-05-05 11:20:36

标签: android android-actionbar navigation-drawer android-togglebutton

即使在编码后,我也无法在预览中看到切换按钮。我错过了什么吗?

我想在该切换按钮上实现导航抽屉,它将从右向左打开,再次点击它将关闭。

以下是我的代码:

public class entryActivity extends ActionBarActivity {

    private String[] mMenuItems;
    private DrawerLayout mDrawerLayout;
    private ListView mDrawerList;
    private ActionBarDrawerToggle actionBarDrawerToggle;
    private CharSequence mDrawerTitle;
    private CharSequence mTitle;


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

        //https://developer.android.com/training/implementing-navigation/nav-drawer.html
        mMenuItems = getResources().getStringArray(R.array.menu_items);
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerList = (ListView) findViewById(R.id.left_drawer);

        // Set the adapter for the list view
        mDrawerList.setAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, mMenuItems));
        ActionBar actionBar = getSupportActionBar();

        actionBar.setHomeButtonEnabled(true);


        actionBarDrawerToggle = new ActionBarDrawerToggle(
                this,
                mDrawerLayout,
                R.string.open,
                R.string.close
        ){
            public void onDrawerClosed(View view) {
                super.onDrawerClosed(view);
                getActionBar().setTitle(mTitle);
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }

            /** Called when a drawer has settled in a completely open state. */
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                getActionBar().setTitle(mDrawerTitle);
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }
        };

        mDrawerLayout.setDrawerListener(actionBarDrawerToggle);
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        if(actionBarDrawerToggle.onOptionsItemSelected(item)){
            return true;
        }

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }


}

enter image description here

3 个答案:

答案 0 :(得分:0)

在onCreate方法中设置它。

actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);

答案 1 :(得分:0)

尝试添加setDisplayHomeAsUpEnabled(),就像<dependency> <groupId>org.scala-lang</groupId> <artifactId>scala-xml</artifactId> <version>2.11.0-M4</version> </dependency>

一样

汉堡菜单选项:http://codetheory.in/android-navigation-drawer/

答案 2 :(得分:0)

您需要致电public function indexAction() { $this->HeadTitlePlugin()->setHeadTitle("Signup"); // other codes }

public function destroy($id, DeletePivotRequest $request)
{
    Resource::findOrFail($id);
}

查看完整示例:https://developer.android.com/training/implementing-navigation/nav-drawer.html