0
這是我的代碼:Android開放式的drawerlayout
package com.example.androidtestnavigationdrawer;
import android.os.Bundle;
import android.app.Activity;
import android.app.Fragment;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends ActionBarActivity {
private String[] mPlanetTitles;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPlanetTitles = new String[5];
mPlanetTitles[0] = "Roma";
mPlanetTitles[1] = "Milan";
mPlanetTitles[2] = "TOTTI";
mPlanetTitles[3] = "Juve";
mPlanetTitles[4] = "JJJ";
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
mDrawerList.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_list_item, mPlanetTitles));
// mDrawerList.setOnItemLongClickListener(new DrawerItemClickListner());
ActionBar action = getSupportActionBar();
action.setDisplayHomeAsUpEnabled(true);
action.setHomeButtonEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_launcher, R.string.hello_world,
R.string.hello_world);
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
我不知道我應該爲了打開抽屜佈局做。請幫忙嗎?
我對這個'com.actionbarsherlock.view.MenuItem遇到錯誤' – user2059935
好的,然後使用簡單的菜單。 其實我用sherlock lib進入我的項目這就是爲什麼我用來寫...... – Namy
代碼完美的工作,但爲什麼這個'DrawerItemClickListener'?這個類不使用這就是爲什麼日食狀態 – user2059935