本文介绍了行动福尔摩斯酒吧和抽屉布局上4.0而不是2.3上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用行动福尔摩斯图书馆DrawerLayout及其工作罚款4.0,但不工作的2.3.6。
这里是主要活动

I'm using Action Sherlock Library and DrawerLayout its working fine on 4.0 but not working on 2.3.6.Here is the Main Activity

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中

And layout file 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>

这是我的错误日志

here is my error log

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

请告诉我,什么是错。我无法弄清楚。
由于提前

Please tell me whats wrong. I am not able to figure it out.Thanks in Advance

推荐答案

扩展与SherlockFragmentActivity类与片段使用ActionBarSherlock。

Extend your class with SherlockFragmentActivity to use ActionBarSherlock with fragments.

public class MainActivity_navi extends SherlockFragmentActivity {

这篇关于行动福尔摩斯酒吧和抽屉布局上4.0而不是2.3上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 13:12