GetSupportActionBar返回null [英] GetSupportActionBar return null

查看:146
本文介绍了GetSupportActionBar返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

启动第二个活动后,没有操作栏。当我调用GetSupportActivity时,它返回null。为什么?我有minSdkVersion 10和targetSdkVersion15。

After I started my second Activity, there isn't the ActionBar. When I call GetSupportActivity, it returns null. Why? I have minSdkVersion 10 and targetSdkVersion 15.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test.myapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="15"
        />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.Sherlock.Light" 
        >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" 
            android:windowSoftInputMode="stateHidden"
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity 
            android:name=".ShowMusic2"
            android:label="Search Results">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
    </application>

</manifest>

这是我第二个活动(ShowMusic2)的OnCreate。这是一个ListActivity。

This is the OnCreate of my second activity (ShowMusic2). It is a ListActivity.

public class ShowMusic2 extends SherlockListActivity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        showMusic = getIntent();
        pkgName = getPackageName();
        html = (String)showMusic.getStringExtra(pkgName + ".html");     
        new populateListView().execute(songs.toArray(new Song[songs.size()]));
        adapter =new SongAdapter(this,R.layout.list_item1, songs.toArray(new Song[songs.size()]));
        setListAdapter(adapter);
    }


推荐答案

我还没有玩过SherlockListActivity太多...但是这里是黑暗中的镜头......尝试移动

I havent played around with SherlockListActivity too much...but here's a shot in the dark....try moving

   getSupportActionBar().setDisplayHomeAsUpEnabled(true);

到您的onStart方法重写中,而不是onCreate

into your onStart method override instead of the onCreate

这篇关于GetSupportActionBar返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆