Search code examples
androidandroid-actionbardrawable

Getting null at setting actionBar icon


I've got problem with my actionBar. Tryin' to set an icon but still getting null :/ Here's code :

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getActionBar().setIcon(R.drawable.logo);
        getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#51717e")));

    }

Ofc I've got logo in my drawable folder. Both lines are incorrect - Icon and Background color. Help :/


Solution

  • You are getting Actionbar null because the Theme don't have ActionBar. Try to set the background and icon in your styles.xml