最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實(shí)現(xiàn)底部導(dǎo)航欄功能(選項(xiàng)卡)

 更新時(shí)間:2015年12月23日 11:50:19   投稿:lijiao  
這篇文章主要介紹了Android實(shí)現(xiàn)底部導(dǎo)航欄功能,可以隨意切換不同的頁面,實(shí)現(xiàn)選項(xiàng)卡功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

現(xiàn)在很多android的應(yīng)用都采用底部導(dǎo)航欄的功能,這樣可以使得用戶在使用過程中隨意切換不同的頁面,現(xiàn)在我采用TabHost組件來自定義一個(gè)底部的導(dǎo)航欄的功能。

我們先看下該demo實(shí)例的框架圖:

其中各個(gè)類的作用以及資源文件就不詳細(xì)解釋了,還有資源圖片(在該Demo中借用了其它應(yīng)用程序的資源圖片)也不提供了,大家可以自行更換自己需要的資源圖片。直接上各個(gè)布局文件或各個(gè)類的代碼:

1、res/layout目錄下的 maintabs.xml 源碼:

<?xml version="1.0" encoding="UTF-8"?> 
<TabHost android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" 
 xmlns:android="http://schemas.android.com/apk/res/android"> 
 <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> 
 <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="0.0dip" android:layout_weight="1.0" /> 
 <TabWidget android:id="@android:id/tabs" android:visibility="gone" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.0" /> 
 <RadioGroup 
 android:gravity="center_vertical" android:layout_gravity="bottom" android:orientation="horizontal" android:id="@id/main_radio" android:background="@drawable/maintab_toolbar_bg" 
 android:layout_width="fill_parent" android:layout_height="wrap_content"> 
 <RadioButton android:id="@id/radio_button0" android:layout_marginTop="2.0dip" android:text="@string/main_home" android:drawableTop="@drawable/icon_1_n" style="@style/main_tab_bottom" /> 
 <RadioButton android:id="@id/radio_button1" android:layout_marginTop="2.0dip" android:text="@string/main_news" android:drawableTop="@drawable/icon_2_n" style="@style/main_tab_bottom" /> 
 <RadioButton android:id="@id/radio_button2" android:layout_marginTop="2.0dip" android:text="@string/main_manage_date" android:drawableTop="@drawable/icon_3_n" style="@style/main_tab_bottom" /> 
 <RadioButton android:id="@id/radio_button3" android:layout_marginTop="2.0dip" android:text="@string/main_friends" android:drawableTop="@drawable/icon_4_n" style="@style/main_tab_bottom" /> 
 <RadioButton android:id="@id/radio_button4" android:layout_marginTop="2.0dip" android:text="@string/more" android:drawableTop="@drawable/icon_5_n" style="@style/main_tab_bottom" /> 
 </RadioGroup> 
 </LinearLayout> 
</TabHost> 

2、res/drawable 下的 home_btn_bg.xml 源碼:

<selector 
 xmlns:android="http://schemas.android.com/apk/res/android"> 
 <item android:state_focused="true" android:state_enabled="true" android:state_pressed="false" android:drawable="@drawable/home_btn_bg_s" /> 
 <item android:state_enabled="true" android:state_pressed="true" android:drawable="@drawable/home_btn_bg_s" /> 
 <item android:state_enabled="true" android:state_checked="true" android:drawable="@drawable/home_btn_bg_d" /> 
 <item android:drawable="@drawable/transparent" /> 
</selector> 

3、res/values 下的源碼:dimens.xml源碼:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
 
 <dimen name="bottom_tab_font_size">10.0sp</dimen> 
 <dimen name="bottom_tab_padding_up">5.0dip</dimen> 
 <dimen name="bottom_tab_padding_drawable">2.0dip</dimen> 
 <dimen name="switch_logo_bottom_padding">30.0sp</dimen> 
 <dimen name="widget_height">100.0dip</dimen> 
 <dimen name="sta_height">48.0dip</dimen> 
 <dimen name="large_padding_length">20.0dip</dimen> 
 <dimen name="widget_write_margin_top">19.0dip</dimen> 
 <dimen name="widget_write_margin_left">10.0dip</dimen> 
 <dimen name="widget_content_margin_top">20.0dip</dimen> 
 <dimen name="widget_content_margin_left">10.0dip</dimen> 
 <dimen name="widget_logo_size">35.0dip</dimen> 
 <dimen name="title_height">74.0dip</dimen> 
 <dimen name="new_blog_size">70.0dip</dimen> 
 <dimen name="emotion_item_view_height">13.299988dip</dimen> 
 <dimen name="splash_test_top_margin_top">20.0dip</dimen> 
 <dimen name="splash_test_center_margin_right">0.0dip</dimen> 
 <dimen name="title_text_size">20.0sp</dimen> 
 <dimen name="normal_padding_length">10.0dip</dimen> 
 <dimen name="no_result_padding_length">50.0dip</dimen> 
 
</resources> 

drawables.xml源碼:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
 
 <item type="drawable" name="ltgray">#fff4f4f4</item> 
 <item type="drawable" name="ltyellow">#fffff4db</item> 
 <item type="drawable" name="black">#ff000000</item> 
 <item type="drawable" name="transparent">#00000000</item> 
 <item type="drawable" name="widget_edit_block_bg_normal">@android:color/transparent</item> 
 <item type="drawable" name="transparent_background">#99000000</item> 
 <item type="drawable" name="list_background">#fff4f4f4</item> 
 <item type="drawable" name="namcard_picker_bkg_normal">#ff272727</item> 
 <item type="drawable" name="namcard_picker_bkg_hover">#ff333333</item> 
 
</resources> 

ids.xml源碼:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
 
 <item type="id" name="main_radio">false</item> 
 <item type="id" name="radio_button0">false</item> 
 <item type="id" name="radio_button1">false</item> 
 <item type="id" name="radio_button2">false</item> 
 <item type="id" name="radio_button3">false</item> 
 <item type="id" name="radio_button4">false</item> 
 
</resources> 

strings.xml源碼:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
 <string name="hello">Hello World, MainTabActivity!</string> 
 <string name="app_name">TabDemo</string> 
 <string name="main_news">消息</string> 
 <string name="main_home">首頁</string> 
 <string name="more">更多</string> 
 <string name="main_manage_date">時(shí)間</string> 
 <string name="main_friends">好友</string> 
</resources> 

styles.xml源碼:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
 
 <style name="main_tab_bottom"> 
 <item name="android:textSize">@dimen/bottom_tab_font_size</item> 
 <item name="android:textColor">#ffffffff</item> 
 <item name="android:ellipsize">marquee</item> 
 <item name="android:gravity">center_horizontal</item> 
 <item name="android:background">@drawable/home_btn_bg</item> 
 <item name="android:paddingTop">@dimen/bottom_tab_padding_up</item> 
 <item name="android:paddingBottom">2.0dip</item> 
 <item name="android:layout_width">fill_parent</item> 
 <item name="android:layout_height">wrap_content</item> 
 <item name="android:layout_marginBottom">2.0dip</item> 
 <item name="android:button">@null</item> 
 <item name="android:singleLine">true</item> 
 <item name="android:drawablePadding">@dimen/bottom_tab_padding_drawable</item> 
 <item name="android:layout_weight">1.0</item> 
 </style> 
 
</resources> 

4、 src/com.andyidea.tabdemo包下面各個(gè)UI界面類源碼:
MainTabActivity.java源碼:

package com.andyidea.tabdemo; 
 
import android.app.TabActivity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.Window; 
import android.widget.CompoundButton; 
import android.widget.RadioButton; 
import android.widget.CompoundButton.OnCheckedChangeListener; 
import android.widget.TabHost; 
 
public class MainTabActivity extends TabActivity implements OnCheckedChangeListener{ 
 
 private TabHost mTabHost; 
 private Intent mAIntent; 
 private Intent mBIntent; 
 private Intent mCIntent; 
 private Intent mDIntent; 
 private Intent mEIntent; 
 
 /** Called when the activity is first created. */ 
 @Override 
 public void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState); 
 requestWindowFeature(Window.FEATURE_NO_TITLE); 
 setContentView(R.layout.maintabs); 
 
 this.mAIntent = new Intent(this,AActivity.class); 
 this.mBIntent = new Intent(this,BActivity.class); 
 this.mCIntent = new Intent(this,CActivity.class); 
 this.mDIntent = new Intent(this,DActivity.class); 
 this.mEIntent = new Intent(this,EActivity.class); 
 
 ((RadioButton) findViewById(R.id.radio_button0)) 
 .setOnCheckedChangeListener(this); 
 ((RadioButton) findViewById(R.id.radio_button1)) 
 .setOnCheckedChangeListener(this); 
 ((RadioButton) findViewById(R.id.radio_button2)) 
 .setOnCheckedChangeListener(this); 
 ((RadioButton) findViewById(R.id.radio_button3)) 
 .setOnCheckedChangeListener(this); 
 ((RadioButton) findViewById(R.id.radio_button4)) 
 .setOnCheckedChangeListener(this); 
 
 setupIntent(); 
 } 
 
 @Override 
 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
 if(isChecked){ 
 switch (buttonView.getId()) { 
 case R.id.radio_button0: 
 this.mTabHost.setCurrentTabByTag("A_TAB"); 
 break; 
 case R.id.radio_button1: 
 this.mTabHost.setCurrentTabByTag("B_TAB"); 
 break; 
 case R.id.radio_button2: 
 this.mTabHost.setCurrentTabByTag("C_TAB"); 
 break; 
 case R.id.radio_button3: 
 this.mTabHost.setCurrentTabByTag("D_TAB"); 
 break; 
 case R.id.radio_button4: 
 this.mTabHost.setCurrentTabByTag("MORE_TAB"); 
 break; 
 } 
 } 
 
 } 
 
 private void setupIntent() { 
 this.mTabHost = getTabHost(); 
 TabHost localTabHost = this.mTabHost; 
 
 localTabHost.addTab(buildTabSpec("A_TAB", R.string.main_home, 
 R.drawable.icon_1_n, this.mAIntent)); 
 
 localTabHost.addTab(buildTabSpec("B_TAB", R.string.main_news, 
 R.drawable.icon_2_n, this.mBIntent)); 
 
 localTabHost.addTab(buildTabSpec("C_TAB", 
 R.string.main_manage_date, R.drawable.icon_3_n, 
 this.mCIntent)); 
 
 localTabHost.addTab(buildTabSpec("D_TAB", R.string.main_friends, 
 R.drawable.icon_4_n, this.mDIntent)); 
 
 localTabHost.addTab(buildTabSpec("MORE_TAB", R.string.more, 
 R.drawable.icon_5_n, this.mEIntent)); 
 
 } 
 
 private TabHost.TabSpec buildTabSpec(String tag, int resLabel, int resIcon, 
 final Intent content) { 
 return this.mTabHost.newTabSpec(tag).setIndicator(getString(resLabel), 
 getResources().getDrawable(resIcon)).setContent(content); 
 } 
} 

其中 AActivity.java 與 BActivity.java ,CActivity.java ,DActivity.java ,EActivity.java 中的源碼都一樣,只是用來表示不同的界面展示,故這里只列出 AActivity.java的源碼:

package com.andyidea.tabdemo; 
 
import android.app.Activity; 
import android.os.Bundle; 
import android.view.Gravity; 
import android.widget.TextView; 
 
public class AActivity extends Activity{ 
 
 @Override 
 public void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState); 
 
 TextView tv = new TextView(this); 
 tv.setText("This is A Activity!"); 
 tv.setGravity(Gravity.CENTER); 
 setContentView(tv); 
 } 
 
} 

最后,大家別忘了在 AndroidManifest.xml 文件中注冊各個(gè) Activity 組件哦。好了,現(xiàn)在我們看下我們程序運(yùn)行的效果圖:

源碼下載:Android實(shí)現(xiàn)底部導(dǎo)航欄功能(選項(xiàng)卡)

到此就實(shí)現(xiàn)了一個(gè)比較流行的底部導(dǎo)航欄的功能了,希望本文所述對大家學(xué)習(xí)Android軟件編程有所幫助。

相關(guān)文章

  • 安卓自定義流程進(jìn)度圖控件實(shí)例代碼

    安卓自定義流程進(jìn)度圖控件實(shí)例代碼

    本篇文章主要介紹了安卓自定義流程進(jìn)度圖控件實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-06-06
  • ScrollView嵌套ListView及ListView嵌套的高度計(jì)算方法

    ScrollView嵌套ListView及ListView嵌套的高度計(jì)算方法

    下面小編就為大家分享一篇ScrollView嵌套ListView及ListView嵌套的高度計(jì)算方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01
  • android?scrollview頂部漸漸消失實(shí)現(xiàn)實(shí)例詳解

    android?scrollview頂部漸漸消失實(shí)現(xiàn)實(shí)例詳解

    這篇文章主要為大家介紹了android?scrollview頂部漸漸消失實(shí)現(xiàn)實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-11-11
  • Android TextView字體顏色設(shè)置方法小結(jié)

    Android TextView字體顏色設(shè)置方法小結(jié)

    這篇文章主要介紹了Android TextView字體顏色設(shè)置方法,結(jié)合實(shí)例形式總結(jié)分析了Android開發(fā)中TextView設(shè)置字體顏色的常用技巧,需要的朋友可以參考下
    2016-02-02
  • Android TextView兩端對齊解決辦法

    Android TextView兩端對齊解決辦法

    這篇文章主要介紹了Android TextView兩端對齊解決辦法的相關(guān)資料,需要的朋友可以參考下
    2017-06-06
  • android用PopWindow做下拉框?qū)嵗a

    android用PopWindow做下拉框?qū)嵗a

    本篇文章主要介紹了android用PopWindow做下拉框?qū)嵗a,具有一定的參考價(jià)值,有興趣的可以了解一下。
    2017-01-01
  • android實(shí)現(xiàn)拍照或從相冊選取圖片

    android實(shí)現(xiàn)拍照或從相冊選取圖片

    這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)拍照或從相冊選取圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-03-03
  • Android 中LayoutInflater.inflate()方法的介紹

    Android 中LayoutInflater.inflate()方法的介紹

    這篇文章主要介紹了Android 中LayoutInflater.inflate()方法的介紹的相關(guān)資料,希望通過本文大家能掌握這部分內(nèi)容,需要的朋友可以參考下
    2017-09-09
  • Android利用FlexboxLayout輕松實(shí)現(xiàn)流動(dòng)布局

    Android利用FlexboxLayout輕松實(shí)現(xiàn)流動(dòng)布局

    flexbox是屬于CSS的一種布局方案,可以簡單、完整、響應(yīng)式的實(shí)現(xiàn)各種頁面布局。谷歌將其引入以提高復(fù)雜布局的能力。下面這篇文章主要給大家介紹了在Android中利用FlexboxLayout輕松實(shí)現(xiàn)流動(dòng)布局的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-04-04
  • 性能分析工具Systrace的使用及說明

    性能分析工具Systrace的使用及說明

    這篇文章主要介紹了性能分析工具Systrace的使用及說明,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-03-03

最新評論

炉霍县| 衢州市| 新建县| 富锦市| 楚雄市| 民权县| 浦江县| 芦山县| 中山市| 平南县| 德化县| 朝阳区| 平顺县| 黄骅市| 平定县| 余干县| 施秉县| 洪江市| 吉林省| 巴林左旗| 白城市| 扎赉特旗| 理塘县| 无极县| 土默特右旗| 大邑县| 郸城县| 建德市| 五原县| 扶绥县| 普洱| 陆丰市| 巴林右旗| 石林| 抚顺市| 纳雍县| 综艺| 嘉定区| 汝州市| 美姑县| 邓州市|