andrid底部导航栏设计.docx

上传人:b****5 文档编号:4098725 上传时间:2022-11-27 格式:DOCX 页数:8 大小:59.71KB
下载 相关 举报
andrid底部导航栏设计.docx_第1页
第1页 / 共8页
andrid底部导航栏设计.docx_第2页
第2页 / 共8页
andrid底部导航栏设计.docx_第3页
第3页 / 共8页
andrid底部导航栏设计.docx_第4页
第4页 / 共8页
andrid底部导航栏设计.docx_第5页
第5页 / 共8页
点击查看更多>>
下载资源
资源描述

andrid底部导航栏设计.docx

《andrid底部导航栏设计.docx》由会员分享,可在线阅读,更多相关《andrid底部导航栏设计.docx(8页珍藏版)》请在冰豆网上搜索。

andrid底部导航栏设计.docx

andrid底部导航栏设计

Android应用底部导航栏(选项卡)实例

现在很多android的应用都采用底部导航栏的功能,这样可以使得用户在使用过程中随意切换不同的页面,现在我采用TabHost组件来自定义一个底部的导航栏的功能。

我们先看下该demo实例的框架图:

 

其中各个类的作用以及资源文件就不详细解释了,还有资源图片(在该Demo中借用了其它应用程序的资源图片)也不提供了,大家可以自行更换自己需要的资源图片。

直接上各个布局文件或各个类的代码:

[1] res/layout目录下的maintabs.xml 源码:

[html]

xmlversion="1.0"encoding="UTF-8"?

id="@android:

id/tabhost"android:

layout_width="fill_parent"android:

layout_height="fill_parent" 

 xmlns:

android=" 

   

orientation="vertical"android:

layout_width="fill_parent"android:

layout_height="fill_parent"> 

       

id="@android:

id/tabcontent"android:

layout_width="fill_parent"android:

layout_height="0.0dip"android:

layout_weight="1.0"/> 

       

id="@android:

id/tabs"android:

visibility="gone"android:

layout_width="fill_parent"android:

layout_height="wrap_content"android:

layout_weight="0.0"/> 

           

               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"> 

               

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"/> 

               

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"/> 

               

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"/> 

               

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"/> 

               

id="@id/radio_button4"android:

layout_marginTop="2.0dip"android:

text="@string/more"android:

drawableTop="@drawable/icon_5_n"style="@style/main_tab_bottom"/> 

            

    

 

[2]res/drawable下的home_btn_bg.xml源码:

[html]

xmlversion="1.0"encoding="UTF-8"?

 xmlns:

android=" 

   

state_focused="true"android:

state_enabled="true"android:

state_pressed="false"android:

drawable="@drawable/home_btn_bg_s"/> 

   

state_enabled="true"android:

state_pressed="true"android:

drawable="@drawable/home_btn_bg_s"/> 

   

state_enabled="true"android:

state_checked="true"android:

drawable="@drawable/home_btn_bg_d"/> 

   

drawable="@drawable/transparent"/> 

 

[3]res/values下的源码:

dimens.xml源码

[html]

xmlversion="1.0"encoding="utf-8"?

 

 

   10.0sp 

   5.0dip 

   2.0dip 

   30.0sp 

   100.0dip 

   48.0dip 

   20.0dip 

   19.0dip 

   10.0dip 

   20.0dip 

   10.0dip 

   35.0dip 

   74.0dip 

   70.0dip 

   13.299988dip 

   20.0dip 

   0.0dip 

   20.0sp 

   10.0dip 

   50.0dip 

 

 

 

drawables.xml源码:

[html]

xmlversion="1.0"encoding="utf-8"?

 

 

   #fff4f4f4 

   #fffff4db 

   #ff000000 

   #00000000 

   @android:

color/transparent 

   #99000000 

   #fff4f4f4 

   #ff272727 

   #ff333333 

 

 

 

ids.xml源码:

[html]

xmlversion="1.0"encoding="utf-8"?

 

 

   false 

   false 

   false 

   false 

   false 

   false 

 

 

 

strings.xml源码:

[html]

xmlversion="1.0"encoding="utf-8"?

 

   HelloWorld,MainTabActivity!

 

   TabDemo 

   消息 

   首页 

   更多 

   时间 

   好友 

 

 

styles.xml源码:

[html]

xmlversion="1.0"encoding="utf-8"?

 

 

     

       

textSize">@dimen/bottom_tab_font_size 

       

textColor">#ffffffff 

       

ellipsize">marquee 

       

gravity">center_horizontal 

       

background">@drawable/home_btn_bg 

       

paddingTop">@dimen/bottom_tab_padding_up 

       

paddingBottom">2.0dip 

       

layout_width">fill_parent 

       

layout_height">wrap_content 

       

layout_marginBottom">2.0dip 

       

button">@null 

       

singleLine">true 

       

drawablePadding">@dimen/bottom_tab_padding_drawable 

       

layout_weight">1.0 

    

 

 

 

[4]src/com.andyidea.tabdemo包下面各个UI界面类源码:

MainTabActivity.java源码:

[html]

packagecom.andyidea.tabdemo; 

 

importandroid.app.TabActivity; 

importandroid.content.Intent; 

importandroid.os.Bundle; 

importandroid.view.Window; 

importandroid.widget.CompoundButton; 

importandroid.widget.RadioButton; 

importandroid.widget.CompoundButton.OnCheckedChangeListener; 

importandroid.widget.TabHost; 

 

publicclassMainTabActivityextendsTabActivityimplementsOnCheckedChangeListener{ 

     

   privateTabHostmTabHost; 

   privateIntentmAIntent; 

   privateIntentmBIntent; 

   privateIntentmCIntent; 

   privateIntentmDIntent; 

   privateIntentmEIntent; 

     

   /**Calledwhentheactivityisfirstcreated.*/ 

   @Override 

   publicvoidonCreate(BundlesavedInstanceState){ 

       super.onCreate(savedInstanceState); 

       requestWindowFeature(Window.FEATURE_NO_TITLE); 

       setContentView(R.layout.maintabs); 

         

       this.mAIntent=newIntent(this,AActivity.class); 

       this.mBIntent=newIntent(this,BActivity.class); 

       this.mCIntent=newIntent(this,CActivity.class); 

       this.mDIntent=newIntent(this,DActivity.class); 

       this.mEIntent=newIntent(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 

   publicvoidonCheckedChanged(CompoundButtonbuttonView,booleanisChecked){ 

       if(isChecked){ 

           switch(buttonView.getId()){ 

           caseR.id.radio_button0:

 

               this.mTabHost.setCurrentTabByTag("A_TAB"); 

               break; 

           caseR.id.radio_button1:

 

               this.mTabHost.setCurrentTabByTag("B_TAB"); 

               break; 

           caseR.id.radio_button2:

 

               this.mTabHost.setCurrentTabByTag("C_TAB"); 

               break; 

           caseR.id.radio_button3:

 

               this.mTabHost.setCurrentTabByTag("D_TAB"); 

               break; 

           caseR.id.radio_button4:

 

               this.mTabHost.setCurrentTabByTag("MORE_TAB"); 

               break; 

           } 

       } 

         

   } 

     

   privatevoidsetupIntent(){ 

       this.mTabHost=getTabHost(); 

       TabHostlocalTabHost=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.dra

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 小学教育 > 数学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1