AndroidUI組件之ActionBar

來源:互聯網
上載者:User

標籤:ext   button   androi   自己的   切換   protected   prot   apk   tail   

有一段時間沒有寫博文了,發現自己的博文的完整度不是非常好。就拿AndroidUI組件這一塊。一直沒有更新完。我會儘快更新。好了。不多說了,今天來看一下ActionBar。

依照以往的作風。知識點都以代碼凝視的形式在源碼中。

 

package com.gc.actionbardemo;/** * 1、活動條(ActionBar)是Android3.0的重要更新之中的一個。

ActionBar位於傳統標題列的位置 * 也就是顯示的螢幕的頂部。ActionBar可顯示應用的表徵圖和Activity標題---也就是應用 * 程式頂部顯示的內容。除此之外。ActionBar的右邊還能夠顯示活動項。 * 2、ActionBar提供了例如以下功能 * (1)顯示選項菜單的功能表項目(將功能表項目顯示成Action Item) * (2)使用程式表徵圖作為返回Home主屏或向上的導航操作 * (3)提供互動式View作為Action View * (4)提供基於Tab的導航方式,可用於切換多個Fragment * (5)提供基於下拉的導航方式 * 3、假設希望關閉ActionBar。能夠設定該應用的主題為Xxx.NoActionBar * 4、一旦關閉了ActionBar。該Android應用將不能使用ActionBar * 5、實際項目中。通常推薦使用代碼來控制ActionBar顯示、隱藏,ActionBar * 提供了例如以下方法來控制顯示、隱藏。 * show():顯示ActionBar * hide():隱藏ActionBar */import android.os.Bundle;import android.app.ActionBar;import android.app.Activity;import android.view.Menu;import android.view.View;/** * * @author Android將軍 * */public class ActionBarTest extends Activity {private ActionBar actionBar;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_action_bar_test);//擷取該Activity的ActionBar//僅僅有當應用主題沒有關閉ActionBar時,該代碼才幹返回ActionBaractionBar=getActionBar();}//為“顯示ActionBar”button定義事件處理方法public void showActionBar(View source){//顯示ActionBaractionBar.show();}//為“隱藏ActionBar”button定義事件處理方法public void hideActionBar(View source){//隱藏ActionBaractionBar.hide();}}


 該Activity所相應的布局檔案是activity_action_bar_test,代碼例如以下所看到的:

<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"   >    <Button        android:onClick="showActionBar"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="顯示ActionBar" />    <Button        android:onClick="hideActionBar"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="隱藏ActionBar" /></LinearLayout>

效果演示範範例如以下:


 

轉載請註明出處:http://blog.csdn.net/android_jiangjun/article/details/38230733

AndroidUI組件之ActionBar

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.