ActionBar use it for back

Costas

Administrator
Staff member
JavaScript:
//values.xml
    //add this
    <style name="AppBaseThemeActionBar" parent="android:Theme.Holo.Light.DarkActionBar">
        <item name="android:windowNoTitle">false</item>
    </style>
    //add this

    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
        <item name="android:windowNoTitle">true</item>
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <item name="android:windowNoTitle">true</item>
    </style>
 
JavaScript:
        <activity
            android:name=".Product_Detail"
            android:parentActivityName="com.x.x.MainActivity"
            >> android:theme="@android:style/Theme.Holo.Light.DarkActionBar"
            android:label="@string/title_activity_product__detail" >
        </activity>
 
when activity is sure that called from one parent, there is a xml property (line3^). No code needed... click&return :)
 
JavaScript:
public class Product_Detail extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_product_detail);

		getActionBar().setHomeButtonEnabled(true);
		getActionBar().setDisplayHomeAsUpEnabled(true);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.product__detail, menu);
		return true;
	}
 
otherwise you can use the classic way :
JavaScript:
	@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                // app icon in action bar clicked; goto parent activity.
                this.finish();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

Snap155.png



customize the appbar logo
In AndroidManifest.xml add line: android:logo="@drawable/logo"

http://stackoverflow.com/a/3438352/1320686
generator - http://jgilfelt.github.io/android-actionbarstylegenerator/
JavaScript:
@Override
public void setActionBar(String heading) {
    // TODO Auto-generated method stub

    com.actionbarsherlock.app.ActionBar actionBar = getSupportActionBar();
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.title_bar_gray)));
    actionBar.setTitle(heading);
    actionBar.show();

}
 
Top