博客
关于我
TabHost自定义标签页(二)
阅读量:201 次
发布时间:2019-02-28

本文共 2498 字,大约阅读时间需要 8 分钟。

TabHostActivity.java
package com.example.a20200712;import android.app.Activity;import android.graphics.drawable.ColorDrawable;import android.graphics.drawable.Drawable;import android.os.Bundle;import android.view.View;import android.widget.EditText;import android.widget.ImageView;import android.widget.TabHost;import android.widget.TextView;import android.widget.Toast;import androidx.annotation.Nullable;import androidx.appcompat.app.AppCompatActivity;import org.w3c.dom.Text;public class TabHostActivity extends AppCompatActivity {    private TabHost tabHost = null;    @Override    protected void onCreate(@Nullable Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.tab_host_layout);        tabHost = (TabHost) this.findViewById(R.id.tab_host_layout);        tabHost.setup();        TabHost.TabSpec tabSpec1 = tabHost.newTabSpec("host_tab_layout_page1");        //tabSpec1.setIndicator("第一页",getResources().getDrawable(R.drawable.spring1));        tabSpec1.setIndicator(getPageView("第一页", R.drawable.spring1));        tabSpec1.setContent(R.id.host_tab_layout_page1);        tabHost.addTab(tabSpec1);        TabHost.TabSpec tabSpec2 = tabHost.newTabSpec("host_tab_layout_page2");        // tabSpec2.setIndicator("第二页",getResources().getDrawable(R.drawable.spring1));        tabSpec2.setIndicator(getPageView("第二页", R.drawable.spring1));        tabSpec2.setContent(R.id.host_tab_layout_page2);        tabHost.addTab(tabSpec2);        TabHost.TabSpec tabSpec3 = tabHost.newTabSpec("host_tab_layout_page3");        //tabSpec3.setIndicator("第三页",getResources().getDrawable(R.drawable.spring1));        tabSpec3.setIndicator(getPageView("第三页", R.drawable.spring1));        tabSpec3.setContent(R.id.host_tab_layout_page3);        tabHost.addTab(tabSpec3);        //默认打开哪个标签页        tabHost.setCurrentTab(0);    }    private View getPageView(String subject, int resId) {        View view = getLayoutInflater().inflate(R.layout.tab_host_head_page_layout, null);        TextView textView = view.findViewById(R.id.tab_host_head_page_title);        return view;    }}

主UI  

tab_host_layout.xml

自定义头UI

tab_host_head_page_layout.xml

在drawable目录下建一个动态图

tab_host_selected.xml

 

 

 

转载地址:http://evqn.baihongyu.com/

你可能感兴趣的文章
MAC M1大数据0-1成神篇-25 hadoop高可用搭建
查看>>
mac mysql 进程_Mac平台下启动MySQL到完全终止MySQL----终端八步走
查看>>
Mac OS 12.0.1 如何安装柯美287打印机驱动,刷卡打印
查看>>
MangoDB4.0版本的安装与配置
查看>>
Manjaro 24.1 “Xahea” 发布!具有 KDE Plasma 6.1.5、GNOME 46 和最新的内核增强功能
查看>>
mapping文件目录生成修改
查看>>
MapReduce程序依赖的jar包
查看>>
mariadb multi-source replication(mariadb多主复制)
查看>>
MariaDB的简单使用
查看>>
MaterialForm对tab页进行隐藏
查看>>
Member var and Static var.
查看>>
memcached高速缓存学习笔记001---memcached介绍和安装以及基本使用
查看>>
memcached高速缓存学习笔记003---利用JAVA程序操作memcached crud操作
查看>>
Memcached:Node.js 高性能缓存解决方案
查看>>
memcache、redis原理对比
查看>>
memset初始化高维数组为-1/0
查看>>
Metasploit CGI网关接口渗透测试实战
查看>>
Metasploit Web服务器渗透测试实战
查看>>
MFC模态对话框和非模态对话框
查看>>
Moment.js常见用法总结
查看>>