Android TabHost實現新浪微博菜單介面

來源:互聯網
上載者:User

先上結果圖:


首先是布局檔案main.xml:

                    <frameLayout            android:id="@android:id/tabcontent"            android:layout_width="fill_parent"            android:layout_height="0.0dip"            android:layout_weight="1.0" />                                                                                        
樣式檔案style.xml:

    
資源檔dimens.xml:

    5.0dip3.0dip10.0dip
drawables.xml:

#00000000
stings.xml:

    SinaWeibo    首頁    資訊    我的資料    搜尋    更多
activity檔案:

package com.chao.demo;import com.chao.demo.R;import android.app.TabActivity;import android.content.Intent;import android.os.Bundle;import android.view.Window;import android.widget.RadioGroup;import android.widget.TabHost;import android.widget.RadioGroup.OnCheckedChangeListener;public class MainTabActivity extends TabActivity implementsOnCheckedChangeListener {private RadioGroup mainTab;private TabHost tabhost;private Intent iHome;private Intent iNews;private Intent iInfo;private Intent iSearch;private Intent iMore;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.main);mainTab = (RadioGroup) findViewById(R.id.main_tab);mainTab.setOnCheckedChangeListener(this);tabhost = getTabHost();iHome = new Intent(this, HomeActivity.class);tabhost.addTab(tabhost.newTabSpec("iHome").setIndicator(getResources().getString(R.string.main_home),getResources().getDrawable(R.drawable.icon_1_n)).setContent(iHome));iNews = new Intent(this, NewsActivity.class);tabhost.addTab(tabhost.newTabSpec("iNews").setIndicator(getResources().getString(R.string.main_news),getResources().getDrawable(R.drawable.icon_2_n)).setContent(iNews));iInfo = new Intent(this, MyInfoActivity.class);tabhost.addTab(tabhost.newTabSpec("iInfo").setIndicator(getResources().getString(R.string.main_my_info),getResources().getDrawable(R.drawable.icon_3_n)).setContent(iInfo));iSearch = new Intent(this, SearchActivity.class);tabhost.addTab(tabhost.newTabSpec("iSearch").setIndicator(getResources().getString(R.string.menu_search),getResources().getDrawable(R.drawable.icon_4_n)).setContent(iSearch));iMore = new Intent(this, MoreActivity.class);tabhost.addTab(tabhost.newTabSpec("iMore").setIndicator(getResources().getString(R.string.more),getResources().getDrawable(R.drawable.icon_5_n)).setContent(iMore));}// 監聽器監聽點擊的按鈕 將相應的介面顯示出來@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {switch (checkedId) {case R.id.radio_button0:this.tabhost.setCurrentTabByTag("iHome");break;case R.id.radio_button1:this.tabhost.setCurrentTabByTag("iNews");break;case R.id.radio_button2:this.tabhost.setCurrentTabByTag("iInfo");break;case R.id.radio_button3:this.tabhost.setCurrentTabByTag("iSearch");break;case R.id.radio_button4:this.tabhost.setCurrentTabByTag("iMore");break;}}}
HomeActivity.java:

package com.chao.demo;import android.app.Activity;import android.os.Bundle;import android.widget.TextView;public class HomeActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);TextView textView=new TextView(this);textView.setText("這是首頁?");setContentView(textView);}}
其他介面檔案類似不再給出

完整工程地址:http://download.csdn.net/detail/u014071669/7187077






聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.