欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android  ActionBar控件操作使用詳解

 更新時(shí)間:2023年04月14日 08:28:17   作者:不入流Android開發(fā)  
這篇文章主要介紹了Android  ActionBar控件操作使用,ActionBar是Android常用的導(dǎo)航控件,位于activity的頂部,用于顯示標(biāo)題,導(dǎo)航icon和actions等等

ActionBar是一個(gè)顯示在屏幕頂部的控件,它包括了在左邊顯示的應(yīng)用的logo圖標(biāo)和右邊操作菜單的可見項(xiàng)。

實(shí)現(xiàn)方法

在ActionBar上的圖標(biāo)叫做ActionButtons,可以把不重要的ActionButtons放在ActionOverflows。

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:id="@+id/action_share"
        android:actionProviderClass="android.widget.ShareActionProvider"
        android:showAsAction="ifRoom"
        android:title="@string/share"/>
    <item
        android:id="@+id/action_search"
        android:icon="@drawable/ic_action_search"
        android:showAsAction="ifRoom"
        android:title="@string/search"/>
    <item
        android:id="@+id/action_setting"
        android:showAsAction="always"
        android:title="@string/setting"/>
</menu>

在Activity中:

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        MenuItem shareItem = menu.findItem(R.id.action_share);
        return true;
    }

自定義ActionBar background:

  • 在Theme.xml中新建自定義Style,使其繼承已有的Action Bar Style(Theme.holo)
  • 復(fù)寫其actionBarStyle屬性
  • actionBarStyle屬性值指向另一個(gè)被覆寫了background屬性的Style
  • 指定該background的屬性值

theme.xml:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="CustomActionBarTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/CustomBackground</item>
    </style>
    <style name="CustomBackground" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@drawable/actionbar_background</item>
    </style>

設(shè)置ActionBar為Tab樣式:

ActionBar actionBar = getActionBar(); //for <3.0 getSupportActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        for (int i = 0; i < 3; i++){
            Tab tab = actionBar.newTab();
            tab.setText("Tab" + i);
            tab.setTabListener(null);
            actionBar.addTab(tab);
        }

實(shí)現(xiàn)Tablistener回調(diào)方法:

  ActionBar.TabListener tabListener = new ActionBar.TabListener() {
        @Override
        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            Toast.makeText(MainActivity.this, "TabSelected" + tab.getPosition(), Toast.LENGTH_SHORT).show();
        }
        @Override
        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        }
        @Override
        public void onTabReselected(Tab tab, FragmentTransaction ft) {
        }
    };

啟用Overlay模式

ActionBar占用一定屏幕空間,可以使之自動(dòng)隱藏,但是每次自動(dòng)隱藏又會(huì)導(dǎo)致重新計(jì)算屏幕,可以設(shè)置其為Overlay模式以把ActionBar放在屏幕的上面而不是頂部。

首先需要?jiǎng)?chuàng)建自定義theme,并設(shè)置android.windowActionBarOverlay屬性為true。

<style
        name="CustomActionBarOverlayTheme"
        parent="@android:style/Theme.Holo"
        >
        <item name="android:windowActionBarOverlay">true</item>
    </style>

如果要預(yù)留一定空間,可以指定PaddingTop:

android:paddingTop="?android:attr/actionBarSize"

添加ActionProvider:

menu.xml:

   <item
        android:id="@+id/action_share"
        android:actionProviderClass="android.widget.ShareActionProvider"
        android:showAsAction="ifRoom"
        android:title="@string/share"/>

在Activity代碼中:(當(dāng)前系統(tǒng)中能夠發(fā)送圖片的所有應(yīng)用)

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    MenuItem shareItem = menu.findItem(R.id.action_share);
    mShareActionProvider = (ShareActionProvider) shareItem.getActionProvider();
    mShareActionProvider.setShareIntent(getDefaultIntent());
    return true;
}
private Intent getDefaultIntent() {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("image/*");
    return intent;

到此這篇關(guān)于Android ActionBar控件操作使用詳解的文章就介紹到這了,更多相關(guān)Android ActionBar控件內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 深入淺析Android JSON解析

    深入淺析Android JSON解析

    android中網(wǎng)絡(luò)數(shù)據(jù)傳輸是經(jīng)常被用到的,通常我們使用xml或者json,而json更加輕量,便捷,我們使用的更多。我自己在項(xiàng)目中使用很多,今天就說說android中怎么去解析JSON,幫助自己總結(jié)內(nèi)容,同時(shí)幫助別人少走彎路
    2015-12-12
  • Android實(shí)現(xiàn)按鈕點(diǎn)擊效果

    Android實(shí)現(xiàn)按鈕點(diǎn)擊效果

    本文主要介紹了Android實(shí)現(xiàn)按鈕點(diǎn)擊效果:第一次點(diǎn)擊變色,第二次恢復(fù)。具有很好的參考價(jià)值,下面跟著小編一起來看下吧
    2017-02-02
  • Android 中cookie的處理詳解

    Android 中cookie的處理詳解

    這篇文章主要介紹了Android 中cookie的處理詳解的相關(guān)資料,主要介紹Android 中Cookie 的操作,希望通過本文能幫助到大家,需要的朋友可以參考下
    2017-08-08
  • android橫豎屏切換時(shí)候Activity的生命周期

    android橫豎屏切換時(shí)候Activity的生命周期

    曾經(jīng)遇到過一個(gè)面試題,讓你寫出橫屏切換豎屏Activity的生命周期。現(xiàn)在給大家分析一下他切換時(shí)具體的生命周期是怎么樣的
    2013-01-01
  • android 仿微信demo——注冊(cè)功能實(shí)現(xiàn)(服務(wù)端)

    android 仿微信demo——注冊(cè)功能實(shí)現(xiàn)(服務(wù)端)

    本篇文章主要介紹了微信小程序-閱讀小程序?qū)嵗?,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧,希望能給你們提供幫助
    2021-06-06
  • Android實(shí)現(xiàn)網(wǎng)易嚴(yán)選標(biāo)簽欄滑動(dòng)效果

    Android實(shí)現(xiàn)網(wǎng)易嚴(yán)選標(biāo)簽欄滑動(dòng)效果

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)網(wǎng)易嚴(yán)選標(biāo)簽欄滑動(dòng)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • Android ListView萬能適配器實(shí)例代碼

    Android ListView萬能適配器實(shí)例代碼

    本文主要介紹Android ListView萬能適配器,這里整理了詳細(xì)的資料及實(shí)現(xiàn)代碼,以及實(shí)現(xiàn)效果圖,有需要的小伙伴可以參考下
    2016-09-09
  • Android實(shí)現(xiàn)長截屏功能

    Android實(shí)現(xiàn)長截屏功能

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)長截屏功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-01-01
  • Android OKHttp使用簡介

    Android OKHttp使用簡介

    目前Android端調(diào)用網(wǎng)絡(luò)請(qǐng)求最常用的框架就是OKHttp,目前項(xiàng)目中也經(jīng)常會(huì)用到。介紹下OKHttp的使用場(chǎng)景
    2021-05-05
  • Android 中Notification彈出通知實(shí)現(xiàn)代碼

    Android 中Notification彈出通知實(shí)現(xiàn)代碼

    NotificationManager 是狀態(tài)欄通知的管理類,負(fù)責(zé)發(fā)通知、清除通知等操作。接下來通過本文給大家介紹Android 中Notification彈出通知實(shí)現(xiàn)代碼,需要的的朋友參考下吧
    2017-08-08

最新評(píng)論