I want to build my own app and i want to add an action bar to it.In my main layout i want an action bar with my app name only.In my other layouts/pages i want my page name and a back navigating symbol which navigates back to the previous page.Can anybody tell me how to do this and also can somebody tell me about the default actionbar in android what it does and what do i do with it.
STEP 1 : build.gradle (Application Level)
dependencies {
compile 'com.android.support:appcompat-v7:23.3.0'
}
STEP 2 : AndroidManifest.xml
<application
....
android:theme="@style/Theme.AppCompat.Light.DarkActionBar"/>
STEP 3 : In your activity
public class main extends AppCompatActivity
{
....
@Override
protected void onCreate(Bundle savedInstanceState) {
...
getSupportActionBar().setTitle("Your Activity Title"); // for set actionbar title
getSupportActionBar().setDisplayHomeAsUpEnabled(true); // for add back arrow in action bar
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
int id = item.getItemId();
if (id == android.R.id.home) {
finish();
}
return super.onOptionsItemSelected(item);
}