0

I have a really strange behaviour with my tablet interface (Android > 3). When I launch it, it's like a Android 2* interface with the title at the bottom. And of course when I call the getActionBar() it returns a null.

My min-sdk & target-sdk are well set and I use the SDK Android 3.0 (11). Where am I wrong ?

public class MainScreenActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mainlayout);
    ActionBar bar = getActionBar();
    bar.setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar));

With the last line I get this error :

Caused by: java.lang.NullPointerException
E/AndroidRuntime( 9082):    at com.shoppingscanner.tablet.MainScreenActivity.onCreate(MainScreenActivity.java:21)
E/AndroidRuntime( 9082):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
E/AndroidRuntime( 9082):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1782)
E/AndroidRuntime( 9082):    ... 11 more

My Manifest (Android 3.0 used) :

<uses-sdk
    android:minSdkVersion="5"
    android:targetSdkVersion="11" />

Even if the minSdk is 11, I have this behaviour.

Thanks !

g123k
  • 3,748
  • 6
  • 42
  • 45
  • Try not using minsdk, just for test. Your code hardly support minsdk="5" if it works with actionbar... – Warpzit Dec 14 '11 at 08:32
  • @Warpzit Unfortunately that's the same :/ – g123k Dec 14 '11 at 08:39
  • Now I'm just shooting :) I don't have experience with actionbar but from what I read maybe you should set the background in public boolean onCreateOptionsMenu(Menu menu) – Warpzit Dec 14 '11 at 08:43
  • You should also check for Your application theme. As in my case I was updating older application has theme set to Full screen no Title bar, which I guess was reason for actionBar null. – MobileEvangelist Jul 17 '14 at 09:55
  • Try this and modify it according to your need http://stackoverflow.com/questions/5914791/android-3-0-action-bar-dont-want-to-go – Sagar Devanga Nov 05 '14 at 10:08

1 Answers1

5

You also need your Activity's window to have the title visible. you can take help from here

Deepak Goel
  • 5,624
  • 6
  • 39
  • 53