我使用動作Sherlock圖書館和DrawerLayout其工作良好的4.0但不工作在2.3.6。 這裏是主要活動動作夏洛克酒吧和抽屜佈局4.0上工作但不上2.3
public class MainActivity_navi extends FragmentActivity{
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
RelativeLayout nDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
public ActionBar mActionBar;
public LayoutInflater mInflater;
public View mCustomView;
public TextView mTitleTextView;
private CharSequence mDrawerTitle;
private CharSequence mTitle;
private String[] mPlanetTitles;
protected ActionBarSherlock sherlock = ActionBarSherlock.wrap(this);
SherlockActivity mActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTitle = mDrawerTitle = getTitle();
mPlanetTitles = getResources().getStringArray(R.array.planets_array);
mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
nDrawerList=(RelativeLayout)findViewById(R.id.right_drawer);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
mDrawerList.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_list_item, mPlanetTitles));
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
Button bt=(Button)findViewById(R.id.button1);
sherlock.getActionBar().setDisplayHomeAsUpEnabled(true);
sherlock.getActionBar().setHomeButtonEnabled(true);
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent=new Intent(MainActivity_navi.this,SecondActivity.class);
startActivity(intent);
}
});
mDrawerToggle = new ActionBarDrawerToggle(
this,
mDrawerLayout,
R.drawable.ic_drawer,
R.string.drawer_open,
R.string.drawer_close
) {
public void onDrawerClosed(View view) {
supportInvalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
supportInvalidateOptionsMenu();
}
};}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_navi, menu);
return super.onCreateOptionsMenu(menu);
}
和佈局文件activity_main.xml中
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</FrameLayout>
<ListView
android:id="@+id/left_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
<RelativeLayout
android:id="@+id/right_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="#111">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button1" />
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
這裏是我的錯誤日誌
E/AndroidRuntime(7519): FATAL EXCEPTION: main
E/AndroidRuntime(7519): android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
E/AndroidRuntime(7519): at android.view.LayoutInflater.createView(LayoutInflater.java:518)
E/AndroidRuntime(7519): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
E/AndroidRuntime(7519): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
E/AndroidRuntime(7519): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
E/AndroidRuntime(7519): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
E/AndroidRuntime(7519): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332)
E/AndroidRuntime(7519): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
E/AndroidRuntime(7519): at android.widget.AbsListView.obtainView(AbsListView.java:1609)
E/AndroidRuntime(7519): at android.widget.ListView.makeAndAddView(ListView.java:1772)
E/AndroidRuntime(7519): at android.widget.ListView.fillDown(ListView.java:695)
E/AndroidRuntime(7519): at android.widget.ListView.fillFromTop(ListView.java:752)
E/AndroidRuntime(7519): at android.widget.ListView.layoutChildren(ListView.java:1623)
E/AndroidRuntime(7519): at android.widget.AbsListView.onLayout(AbsListView.java:1439)
E/AndroidRuntime(7519): at android.view.View.layout(View.java:7175)
E/AndroidRuntime(7519): at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:702)
E/AndroidRuntime(7519): at android.view.View.layout(View.java:7175)
E/AndroidRuntime(7519): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
E/AndroidRuntime(7519): at android.view.View.layout(View.java:7175)
E/AndroidRuntime(7519): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
E/AndroidRuntime(7519): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
E/AndroidRuntime(7519): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
E/AndroidRuntime(7519): at android.view.View.layout(View.java:7175)
E/AndroidRuntime(7519): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
E/AndroidRuntime(7519): at android.view.View.layout(View.java:7175)
E/AndroidRuntime(7519): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
E/AndroidRuntime(7519): at android.view.View.layout(View.java:7175)
E/AndroidRuntime(7519): at android.view.ViewRoot.performTraversals(ViewRoot.java:1144)
E/AndroidRuntime(7519): at android.view.ViewRoot.handleMessage(ViewRoot.java:1863)
E/AndroidRuntime(7519): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(7519): at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime(7519): at android.app.ActivityThread.main(ActivityThread.java:3687)
E/AndroidRuntime(7519): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(7519): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(7519): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
E/AndroidRuntime(7519): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
E/AndroidRuntime(7519): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(7519): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime(7519): at java.lang.reflect.Constructor.constructNative(Native Method)
E/AndroidRuntime(7519): at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
E/AndroidRuntime(7519): at android.view.LayoutInflater.createView(LayoutInflater.java:505)
E/AndroidRuntime(7519): ... 35 more
E/AndroidRuntime(7519): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x10102fd a=-1}
E/AndroidRuntime(7519): at android.content.res.Resources.loadDrawable(Resources.java:1681)
E/AndroidRuntime(7519): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
E/AndroidRuntime(7519): at android.view.View.<init>(View.java:1951)
E/AndroidRuntime(7519): at android.widget.TextView.<init>(TextView.java:401)
E/AndroidRuntime(7519): at android.widget.TextView.<init>(TextView.java:394)
E/AndroidRuntime(7519): ... 38 more
請告訴我,什麼是錯。我無法弄清楚。 在前提前感謝
看看這些帖子:stackoverflow.com/questions/16653914/is-there-any-way-use-new-drawerlayout-with-actionbarsharlock,http://stackoverflow.com/questions/16954679/android -drawerlayout-is-not-working-with-viewpager – owe