1. Set ActionBar Title
getActionBar().setTitle("ActionBar Title");
2. Set ActionBar SubTitle
1) show subtitle
getActionBar().setSubtitle("ActionBar Subtitle");2) remove subtitle
getActionBar().setSubtitle(null);
3. Set ActionBar Icon
getActionBar().setIcon(R.drawable.icon);
getActionBar().hide();
5. Show ActionBar
getActionBar().show();
MainActivity.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | package com.example.actionbar; import android.annotation.SuppressLint; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.view.View; @SuppressLint("NewApi") public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getActionBar().setTitle("ActionBar Title"); getActionBar().setSubtitle("ActionBar Subtitle"); } public void onClickActionBarHide(View v) { getActionBar().hide(); } public void onClickActionBarShow(View v) { getActionBar().show(); } } |
acctivity_main.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Hide ActionBar" android:onClick="onClickActionBarHide" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Show ActionBar" android:onClick="onClickActionBarShow" /> </LinearLayout> |
ScreenShot:
1. [Hide ActionBar] Pressed
2. [Show ActionBar] Pressed
댓글 없음:
댓글 쓰기