zoukankan      html  css  js  c++  java
  • android:TabHost总结

    Tabs:标签、选项

    在android布局中,Tabs具有良好的用户体验

    Tabs in the action bar make it easy to explore and switch between different views or functional aspects of your app, or to browse categorized data sets.

    然后总结一下TabHost

    public class

    TabHost

    extends FrameLayout
    implements ViewTreeObserver.OnTouchModeChangeListener
    java.lang.Object
       ↳ android.view.View
         ↳ android.view.ViewGroup
           ↳ android.widget.FrameLayout
             ↳ android.widget.TabHost

    继承自FrameLayout,并实现了触摸监听接口

    Class Overview

     分页式窗口视图的一种容器,包含两种子元素:标签(TabWidget)和对应的内容页(FrameLayout)。TabHost将这些元素统一起来进行控制。

    TabHost的两种实现方法:

    第一种:继承TabActivity,从TabActivity中用getTabHost()方法获取TabHost。

            myTabhost=this.getTabHost();  
            //get Tabhost  
            LayoutInflater.from(this).inflate(R.layout.main, myTabhost.getTabContentView(), true);  
            myTabhost.setBackgroundColor(Color.argb(150, 22, 70, 150));  
              
            myTabhost  
                    .addTab(myTabhost.newTabSpec("One")// make a new Tab  
                            // set the Title and Icon  
                            .setIndicator("A")
                            .setContent(R.id.widget_layout_Blue));  
            // set the layout  
    

    第二种:不继承TabActivity,在布局文件中定义TabHost

      TabWidget的id必须是@android:id/tabs

      FrameLayout的id必须是@android:id/tabcontent

      TabHost的id可以自定义

    <?xml version="1.0" encoding="utf-8"?>  
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    
        android:id="@+id/hometabs"  
        android:orientation="vertical"  
        android:layout_width="fill_parent"    
        android:layout_height="fill_parent">   
        <TabHost android:id="@+id/tabhost"  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content">  
            <LinearLayout  
                android:orientation="vertical"  
                android:layout_width="fill_parent"  
                android:layout_height="fill_parent">  
                  
                <TabWidget android:id="@android:id/tabs"   
                  android:orientation="horizontal"  
                  android:layout_width="wrap_content"  
                  android:layout_height="wrap_content">  
                </TabWidget>  
               
                 <FrameLayout android:id="@android:id/tabcontent"  
                      android:layout_width="wrap_content"  
                      android:layout_height="wrap_content">  
                        <TextView android:id="@+id/view1"  
                            android:layout_width="fill_parent"  
                            android:layout_height="fill_parent"/>  
                        <TextView android:id="@+id/view2"  
                            android:layout_width="fill_parent"  
                            android:layout_height="fill_parent"/>  
                        <TextView android:id="@+id/view3"  
                            android:layout_width="fill_parent"  
                            android:layout_height="fill_parent"/>  
                 </FrameLayout>  
               
             </LinearLayout>  
        </TabHost>  
    </LinearLayout>  
    

    实现代码:

    protected void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);  
            setContentView(R.layout.hometabs);  
              
            TabHost tabHost = (TabHost) findViewById(R.id.tabhost);  
            tabHost.setup();  
            TabWidget tabWidget = tabHost.getTabWidget();  
              
            tabHost.addTab(tabHost.newTabSpec("tab1")  
                    .setIndicator("tab1", getResources().getDrawable(R.drawable.mumule))  
                    .setContent(R.id.view1));  
              
            tabHost.addTab(tabHost.newTabSpec("tab3")  
                    .setIndicator("tab3")  
                    .setContent(R.id.view3));  
              
            tabHost.addTab(tabHost.newTabSpec("tab2")  
                    .setIndicator("tab2")  
                    .setContent(R.id.view2));    
            
        }  
    

      

     

  • 相关阅读:
    CXF对Interceptor拦截器的支持
    SpringBoot 自定义Banner
    Spring Boot应用的后台运行配置
    CXF 开发 REST 服务
    CXF SOAP 及其安全控制
    Cxf 自动生成客户端服务端代码
    跨域的另一种解决方案CORS(CrossOrigin Resource Sharing)跨域资源共享
    从 MVC 到前后端分离
    远程通信的几种选择(RPC,Webservice,RMI,JMS的区别)
    MYSQL
  • 原文地址:https://www.cnblogs.com/skiz/p/2734321.html
Copyright © 2011-2022 走看看