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

Android巧用ActionBar實現(xiàn)下拉式導航

 更新時間:2016年05月25日 14:39:23   作者:summerpxy  
這篇文章主要為大家詳細介紹了Android巧用ActionBar實現(xiàn)下拉式導航的相關資料,具有一定的實用性和參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了ActionBar下拉式導航的實現(xiàn)代碼,供大家參考,具體內容如下

利用Actionbar同樣可以很輕松的實現(xiàn)下拉式的導航方式,若想實現(xiàn)這種效果:

1)actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST) 

2)setListNavigationCallbacks(SpinnerAdapter adapter,ActionBar.OnNavigationListener callback).

首先是創(chuàng)建一個Fragment類:

package ccom.app.main;

import android.annotation.SuppressLint;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.TextView;

@SuppressLint("NewApi")
public class MyFragment extends Fragment {

 @Override
 public View onCreateView(LayoutInflater inflater, ViewGroup container,
   Bundle savedInstanceState) {

  Context context = this.getActivity();

  TextView tv = new TextView(context);

  Bundle arc = this.getArguments();

  int tabs=arc.getInt("key");
  
  tv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
    LayoutParams.WRAP_CONTENT));

  tv.setText("hello actionbar "+tabs);

  return tv;

 }

}

main.xml:

<RelativeLayout 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"
 tools:context=".Main" >

 <LinearLayout
  android:id="@+id/content"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" />

</RelativeLayout>

自定義的用于顯示textview的mytextview.xml:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/text1"
 android:textColor="#fff"
 android:background="#696969"
 android:layout_width="60sp"
 android:layout_height="match_parent"
 android:textAppearance="?android:attr/textAppearanceListItemSmall"
 android:gravity="center_vertical"
 android:paddingStart="?android:attr/listPreferredItemPaddingStart"
 android:minHeight="?android:attr/listPreferredItemHeightSmall"
/>

Main.java

package ccom.app.main;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.widget.ArrayAdapter;

@SuppressLint("NewApi")
public class Main extends Activity implements ActionBar.OnNavigationListener {

 ActionBar actionBar = null;

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

  actionBar = this.getActionBar();

  actionBar.setDisplayShowTitleEnabled(true);

  actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

  actionBar.setListNavigationCallbacks(new ArrayAdapter(Main.this,
    R.layout.mytextview, R.id.text1, new String[] { "tab1", "tab2",
      "tab3" }), this);

 }

 @Override
 public boolean onNavigationItemSelected(int itemPosition, long itemId) {

  MyFragment mf = new MyFragment();
  Bundle bundle = new Bundle();
  bundle.putInt("key", itemPosition + 1);
  mf.setArguments(bundle);

  FragmentTransaction action = this.getFragmentManager()
    .beginTransaction();
  action.replace(R.id.content, mf);
  action.commit();
  return true;
 }

}

實現(xiàn)的效果如圖:

以上就是本文的全部內容,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

  • Flutter實現(xiàn)App功能引導頁

    Flutter實現(xiàn)App功能引導頁

    這篇文章主要為大家詳細介紹了Flutter實現(xiàn)App功能引導頁,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-07-07
  • Android編程開發(fā)之TextView單擊鏈接彈出Activity的方法

    Android編程開發(fā)之TextView單擊鏈接彈出Activity的方法

    這篇文章主要介紹了Android編程開發(fā)之TextView單擊鏈接彈出Activity的方法,涉及Android中TextView控件的相關操作技巧,需要的朋友可以參考下
    2016-01-01
  • Kotlin?lambda表達式入門指南

    Kotlin?lambda表達式入門指南

    在kotlin當中,Lambda表達式是最高等級的,Lambda表達式可以理解為一種匿名函數(shù),是一種高效的類似于函數(shù)式編程的表達式,本文介紹Kotlin?lambda表達式入門指南,感興趣的朋友一起看看吧
    2024-03-03
  • Android中的Permission權限機制介紹

    Android中的Permission權限機制介紹

    這篇文章主要介紹了Android中的Permission權限機制介紹,本文講解了權限策略、權限聲明、權限請求、獲取權限等內容,需要的朋友可以參考下
    2015-04-04
  • 36個Android開發(fā)常用經(jīng)典代碼大全

    36個Android開發(fā)常用經(jīng)典代碼大全

    本篇文章主要介紹了36個Android開發(fā)常用經(jīng)典代碼片段,都是實用的代碼段,具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2016-11-11
  • Android 用SQLite實現(xiàn)事務的方法

    Android 用SQLite實現(xiàn)事務的方法

    本篇文章小編為大家介紹,Android用SQLite實現(xiàn)事務的方法。需要的朋友參考下
    2013-04-04
  • Android VideoView類實例講解

    Android VideoView類實例講解

    本文主要介紹Android VideoView類,這里對VideoView類詳細說明了使用方法,以及示例代碼,有興趣的朋友可以參考下,希望能幫助Android 開發(fā)的朋友
    2016-08-08
  • Android編程簡單實現(xiàn)九宮格示例

    Android編程簡單實現(xiàn)九宮格示例

    這篇文章主要介紹了Android編程簡單實現(xiàn)九宮格,結合具體實例形式分析了Android實現(xiàn)九宮格的具體步驟與相關布局、功能實現(xiàn)技巧,需要的朋友可以參考下
    2017-06-06
  • Android?Studio實現(xiàn)簡單繪圖板

    Android?Studio實現(xiàn)簡單繪圖板

    這篇文章主要為大家詳細介紹了Android?Studio實現(xiàn)簡單繪圖板,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • Android調用系統(tǒng)裁剪的實現(xiàn)方法

    Android調用系統(tǒng)裁剪的實現(xiàn)方法

    下面小編就為大家分享一篇Android調用系統(tǒng)裁剪的實現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-02-02

最新評論