[Solved] Suppress NPE Warning for getSupportActionBar() when called inside Fragments [duplicate]

Because you don’t put checks for NullPointerException ((AppCompatActivity) getActivity()).getSupportActionBar() gives actionbar object but you are calling directly by ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false) that is why system gives warning for NullPointerException. if((getActivity()) != null) { ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); if(actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(false); } } Put above code. Your warning will remove. 1 solved Suppress NPE … Read more

[Solved] How to set background image in actionbar android [closed]

Please read this article: http://cyrilmottier.com/2013/05/24/pushing-the-actionbar-to-the-next-level/ There you will find example and tutorial about your questuion And also you can set action bar background like this. private void setActionBar() { getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setCustomView(R.layout.header_actionbar); getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.actionbar_blue))); TextView tvHeader = (TextView) findViewById(R.id.tv_title_header_actionbar); TextView tvSubheader = (TextView) findViewById(R.id.tv_subtitle_header_actionbar); tvSubheader.setVisibility(View.GONE); } call setActionBar() in your oncreate(). solved How … Read more

[Solved] You need to use a Theme.AppCompat theme (or descendant) with this activity on Android

Change this <style name=”MyMaterialTheme” parent=”MyMaterialTheme.Base”> </style> <style name=”MyMaterialTheme.Base” parent=”Theme.AppCompat.Light.DarkActionBar”> <item name=”windowNoTitle”>true</item> <item name=”windowActionBar”>false</item> <item name=”colorPrimary”>@color/colorPrimary</item> <item name=”colorPrimaryDark”>@color/colorPrimaryDark</item> <item name=”colorAccent”>@color/colorAccent</item> </style> to this <style name=”MyMaterialTheme” parent=”Theme.AppCompat.Light.DarkActionBar”> <item name=”windowNoTitle”>true</item> <item name=”windowActionBar”>false</item> <item name=”colorPrimary”>@color/colorPrimary</item> <item name=”colorPrimaryDark”>@color/colorPrimaryDark</item> <item name=”colorAccent”>@color/colorAccent</item> </style> Full code : <resources> <style name=”MyMaterialTheme” parent=”Theme.AppCompat.Light.DarkActionBar”> <item name=”windowNoTitle”>true</item> <item name=”windowActionBar”>false</item> <item name=”colorPrimary”>@color/colorPrimary</item> <item name=”colorPrimaryDark”>@color/colorPrimaryDark</item> <item name=”colorAccent”>@color/colorAccent</item> </style> </resources> … Read more