1

When I write the following code in the onCreate method :

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // Get a support ActionBar corresponding to this toolbar
        ActionBar ab = getSupportActionBar();

        // Enable the Up button
        ab.setDisplayHomeAsUpEnabled(true);
        ab.setTitle("Vodafone-Dongles");
    }
}

I get:

click here for image description

Otherwise it is OK and shows the default title of the action bar.

Why am I getting it?

user5949689
  • 101
  • 2
  • 8

1 Answers1

0

You should use Toolbar instead of Actionbar:-

insert in your activity:-

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

include following in layout:-

    <Include layout="@layout/app_bar_main"
    android:layout_height="50dp"
    android:layout_width="match_parent" ></Include>

app_bar_main.xml

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/green"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>