activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/rl" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10dp" tools:context=".MainActivity" android:background="#c0d8d5" > <Button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Show App Icon On ActionBar" android:layout_marginTop="10dp" /> </RelativeLayout>
MainActivity.java
package com.cfsuman.me.androidcodesnippets; import android.os.Bundle; import android.app.Activity; import android.view.View; import android.widget.Button; import android.widget.RelativeLayout; import android.app.ActionBar; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Get the widgets reference from XML layout RelativeLayout rl = (RelativeLayout) findViewById(R.id.rl); simpulan Button btn = (Button) findViewById(R.id.btn); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Get the ActionBar of this Activity ActionBar ab = getActionBar(); /* public abstract void setDisplayShowHomeEnabled (boolean showHome) Set whether to include the application home affordance in the action bar. Home is presented as either an activity icon or logo. Parameters showHome : true to show home, false otherwise. */ // Show the app icon on ActionBar ab.setDisplayShowHomeEnabled(true); } }); } }
- How to change ActionBar background color
- How to change ActionBar title
- How to center align ActionBar title
- How to change ActionBar title text color
- How to change ActionBar title text size
- How to change ActionBar title font
- How to change ActionBar title style
- How to create gradient background ActionBar
- How to get ActionBar height
- How to display custom layout in ActionBar
Komentar
Posting Komentar