Search code examples
androidandroid-actionbarmaterial-designandroid-appcompatandroid-actionbar-compat

ActionBar displays only text


I would want to have an actionable that has a custom background, and two icons. One for the app icon and the other replacing the text name of the app.

Currently , for some reason , the only thing that is displayed is text and an invisible margin at the top :

enter image description here

  • I'm using support library (v7) ,my minSdk is 9.

manifest :

...
<activity android:theme="@style/Theme.AppCompat.Light" android:name=".myPagerActivity" /> 
...

Solution

  • You are using the AppCompat version 21 and it is normal.

    The Action Bar follows the material design guidelines and uses a Toolbar. As you can read here:

    The use of application icon plus title as a standard layout is 
        discouraged on API 21 devices and newer.
    

    It is the reason because you are displaying only the test in your Activity.

    You can customize your Toolbar. Something like:

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar">
    
        <!-- your custom views here -->
    
    </android.support.v7.widget.Toolbar>
    

    In your AppCompatActivity:

    Toolbar actionBar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(actionBar);
    
    //Customize your views here...
    

    Finally you have to use a appcompat theme like .NoActionBar