博客
关于我
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/

你可能感兴趣的文章
mysql 用户管理和权限设置
查看>>
MySQL 的 varchar 水真的太深了!
查看>>
mysql 的GROUP_CONCAT函数的使用(group_by 如何显示分组之前的数据)
查看>>
MySQL 的instr函数
查看>>
MySQL 的mysql_secure_installation安全脚本执行过程介绍
查看>>
MySQL 的Rename Table语句
查看>>
MySQL 的全局锁、表锁和行锁
查看>>
mysql 的存储引擎介绍
查看>>
MySQL 的存储引擎有哪些?为什么常用InnoDB?
查看>>
Mysql 知识回顾总结-索引
查看>>
Mysql 笔记
查看>>
MySQL 精选 60 道面试题(含答案)
查看>>
mysql 索引
查看>>
MySQL 索引失效的 15 种场景!
查看>>
MySQL 索引深入解析及优化策略
查看>>
MySQL 索引的面试题总结
查看>>
mysql 索引类型以及创建
查看>>
MySQL 索引连环问题,你能答对几个?
查看>>
Mysql 索引问题集锦
查看>>
Mysql 纵表转换为横表
查看>>