actionbarsherlock getSupportActionBar() return null in android4.0,but in 2.3.3 is ok

Viewed 4652

application use actionbarsherlock,but main activity get getsupportactionbar returns null. AndroidManifest.xml:

    <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Light1Theme" >
    <activity
        android:name=".activity.LogonActivity"
        android:configChanges="orientation|keyboardHidden"
        android:windowSoftInputMode="adjustUnspecified|stateHidden" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    ...

themes.xml:

    <style name="Light1Theme" parent="Theme.Sherlock.Light">

LogonActivity.ava

    extends SherlockActivity implements OnSharedPreferenceChangeListener {
    ...
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //requestWindowFeature(Window.FEATURE_NO_TITLE);
    //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  WindowManager.LayoutParams.FLAG_FULLSCREEN);       

    setContentView(R.layout.logon);

    try{
    final ActionBar ab = getSupportActionBar();
    //return null
    ab.setBackgroundDrawable(getResources().getDrawable(R.drawable.ab_bg_black));
    getSupportActionBar().setIcon(R.drawable.hospital);
    }catch(Exception e){
        Log.e("", e.getMessage());
    }
4 Answers
Related