android DrawerLayout拉开之后就马上停止运行了,这是MainActivity中的代码

RJzz 发布于 2015/05/29 10:15
阅读 419
收藏 0

加载中
0
RJzz
RJzz
public class MainActivity extends ActionBarActivity implements AdapterView.OnItemClickListener {
    private DrawerLayout drawerLayout;
    private ListView listView;
    private ArrayList<String> menuLists;
    private ArrayAdapter<String> adapter;
    private android.support.v4.app.ActionBarDrawerToggle actionBarDrawerToggle;
    private String mtitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        listView = (ListView) findViewById(R.id.left_drawer);
        mtitle = (String)getTitle();
        menuLists = new ArrayList<String>();
        for(int i = 0; i < 5; i++)   {
            menuLists.add("Dota" + i);
        }
        adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, menuLists);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(this);
        actionBarDrawerToggle = new android.support.v4.app.ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer,
                R.string.drawer_open, R.string.drawer_close) {
            @Override
            public void onDrawerOpened(View drawerView) {

                super.onDrawerOpened(drawerView);
                getActionBar().setTitle("ddd");
                invalidateOptionsMenu();
            }

            @Override
            public void onDrawerClosed(View drawerView) {

                super.onDrawerClosed(drawerView);
                getActionBar().setTitle(mtitle);
            }
        };
        drawerLayout.setDrawerListener(actionBarDrawerToggle);
    }



0
火蚁
火蚁

你应该看一下是报的什么错误,有可能是你需要getSupprotActionBar来进行title的设置

返回顶部
顶部