Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the TabHost function of android tab

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "how to use the TabHost function of the android tab". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

First, three xml files are defined, which are called l1.xmlMagneL2.xmlMagneL3.xml. The content of the tab of each tab is a xml file.

Where l1.xml is:

The l2.xml is:

The l3.xml is:

TabActivityDemo2.java:

Package com.example.wenandroid; import android.app.TabActivity;import android.os.Bundle;import android.view.LayoutInflater;import android.widget.TabHost.TabSpec; public class TabActivityDemo2 extends TabActivity {protected void onCreate (Bundle savedInstanceState) {/ / TODO Auto-generated method stub super.onCreate (savedInstanceState); android.widget.TabHost tab=getTabHost (); LayoutInflater lay=LayoutInflater.from (this); lay.inflate (R.layout.l1, tab.getTabContentView (), true) Lay.inflate (R.layout.l2, tab.getTabContentView (), true); lay.inflate (R.layout.l3, tab.getTabContentView (), true); TabSpec t1=tab.newTabSpec ("T1"); TabSpec t2=tab.newTabSpec ("T2"); TabSpec t3=tab.newTabSpec ("T3"); t1.setIndicator ("Tab 1"); t2.setIndicator ("Tab 2") T3.setIndicator ("Tab 3"); t1.setContent (R.id.l1); t2.setContent (R.id.l2); t3.setContent (R.id.l3); tab.addTab (T1); tab.addTab (T2); tab.addTab (T3);}}

The effect is as follows:

This is the end of the content of "how to use the TabHost function of the android tab". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report