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

<?xml version="1.0" encoding="utf-8"?>                                                                                                                                                                        

自定义头UI

tab_host_head_page_layout.xml

<?xml version="1.0" encoding="utf-8"?>    

在drawable目录下建一个动态图

tab_host_selected.xml

<?xml version="1.0" encoding="utf-8"?>

 

TabHost自定义标签页(二)_第1张图片

 

 

更多相关文章

  1. Android保存图片到图库,Android扫描文件到媒体库,Android保存图片
  2. Android 框架学习4:一次读懂热门图片框架 Picasso 源码及流程
  3. 关于android中网络图片下载中oom解决开源框架Afinal的探究
  4. Android App 性能优化之图片优化
  5. 常用组件:android的图片组件ImageView
  6. Android移动图片
  7. Android开发中的drawable文件:shape、layer-list和selector标签

随机推荐

  1. java版数独游戏
  2. Android重拾 — handle
  3. android bluez
  4. Android 全面屏的适配(android-developers
  5. Android之ActionBar、Tabs、Fragment、Vi
  6. Android 手机应用开发经验 之 通过Socket
  7. Android中文翻译 - 测试你的Android Acti
  8. Android 开发者必备的书单
  9. android客户端和网站数据交互的实现(基于H
  10. [Android] 触屏setOnTouchListener实现图