zoukankan      html  css  js  c++  java
  • Android Tab -- 使用TabWidget、TabHost、TabActivity来实现

    原文地址http://blog.csdn.net/crazy1235/article/details/42678877

    TabActivity在API13之后被fragment替代了,所以不建议使用

    效果:点击头像标签,进行切换。

    代码:https://github.com/ldb-github/Layout_Tab

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <TabHost
            android:id="@android:id/tabhost"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                
                <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="false"/>
    
                <FrameLayout
                    android:id="@android:id/tabcontent"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_below="@android:id/tabs">
    
                    <LinearLayout
                        android:id="@+id/tab1"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="#DEB887"
                        android:orientation="vertical">
    
                    </LinearLayout>
    
                    <LinearLayout
                        android:id="@+id/tab2"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="#BCEE68"
                        android:orientation="vertical">
    
                    </LinearLayout>
    
                    <LinearLayout
                        android:id="@+id/tab3"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="#7D9EC0"
                        android:orientation="vertical">
    
                    </LinearLayout>
                </FrameLayout>
                
            </RelativeLayout>
    
        </TabHost>
    
    </LinearLayout>
    tabhost_tabwidget_tabactivity.xml
    public class TabHostTabWidgetTabActivity extends TabActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.tabhost_tabwidget_tabactivity);
    
            TabHost tabHost = getTabHost(); //(TabHost) findViewById(android.R.id.tabhost);
    
            tabHost.addTab(tabHost
                    .newTabSpec("111")
                    .setIndicator("", getResources().getDrawable(R.drawable.wuyong))
                    .setContent(R.id.tab1));
    
            tabHost.addTab(tabHost
                    .newTabSpec("222")
                    .setIndicator("", getResources().getDrawable(R.drawable.gongsunsheng))
                    .setContent(R.id.tab2));
    
            tabHost.addTab(tabHost
                    .newTabSpec("333")
                    .setIndicator("", getResources().getDrawable(R.drawable.likui))
                    .setContent(R.id.tab3));
    
            tabHost.setBackgroundColor(Color.argb(150, 22, 70, 150));
    
            tabHost.setCurrentTab(0);
    
            tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
                @Override
                public void onTabChanged(String tabId) {
                    Toast.makeText(TabHostTabWidgetTabActivity.this, tabId, Toast.LENGTH_SHORT).show();
                }
            });
        }
    }
    TabHostTabWidgetTabActivity.java
  • 相关阅读:
    Windows Server2016环境中安装Oracle12c数据库
    centos7 安装Oracle19C 数据库
    centos7 磁盘分区以及磁盘挂载
    PHP日常开发技巧散记
    代码压缩工具 webpack安装与入门使用【初级】
    程序员修炼之道系列 | 使用曳光弹找到目标
    程序员修炼之道系列 | 不要冲出前灯范围
    程序员修炼之道系列 | 敏捷估算
    程序员修炼之道系列 | “豆腐渣“工程竟然也能做原型
    官宣!禅道与极狐(GitLab)达成深度合作,携手推进开源开放DevOps生态
  • 原文地址:https://www.cnblogs.com/yarightok/p/5639639.html
Copyright © 2011-2022 走看看