-3
import android.app.ActionBar;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;


public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ActionBar.setDisplayShowHomeEnabled(false);
    ActionBar.setDisplayShowTitleEnabled(false);
    ActionBar.setCustomView(R.layout.custom_action_bar);
    ActionBar.setDisplayShowCustomEnabled(true);

    setContentView(R.layout.main);
    }
}

the four lines including ActionBar showing error that: Cannot make a static reference to the non-static method setDisplayShowHomeEnabled(boolean) from the type ActionBar. pls help.

  • All the `ActionBar` methods you are calling are _non-static_, meaning you need to have an instance of ActionBar to call them on. If you call them on the Class name, you don't have an instance of that class. As others have mentioned, you can use `getSupportActionBar()` to get an instance of that class where you are, and run the commands on that. – Dave Lugg May 07 '15 at 18:11

2 Answers2

2

Replace ActionBar with getSupportActionBar() in all four lines.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

Move your setContentView(R.layout.main); after super.onCreate(savedInstanceState);

And, you should not directly do like this,

ActionBar.setDisplayShowHomeEnabled(false);

It should be,

ActionBar actionBar = getSupportActionBar();

actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setCustomView(R.layout.custom_action_bar);
actionBar.setDisplayShowCustomEnabled(true);

So, by summing up your total code should be,

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ActionBar actionBar = getSupportActionBar();

    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setCustomView(R.layout.custom_action_bar);
    actionBar.setDisplayShowCustomEnabled(true);

    }
}
Yuva Raj
  • 3,881
  • 1
  • 19
  • 30