安卓开发怎么使用tabhost控件

安卓开发怎么使用tabhost控件,第1张

setContentView(Rlayoutactivity_main1);

Resources res=getResources();

TabHost tabhost=getTabHost();

TabHostTabSpec spec;

Intent intent;

intent=new Intent()setClass(this, artistsactivityclass);

spec=tabhostnewTabSpec("artists")setIndicator("艺术家",resgetDrawable(Rdrawableicongray))setContent(intent);

tabhostaddTab(spec);

intent=new Intent()setClass(this, albumsactivityclass);

spec=tabhostnewTabSpec("albums")setIndicator("专辑",resgetDrawable(Rdrawableicongray))setContent(intent);

tabhostaddTab(spec);

intent=new Intent()setClass(this, songsactivityclass);

spec=tabhostnewTabSpec("songs")setIndicator("歌曲",resgetDrawable(Rdrawableicongray))setContent(intent);

tabhostaddTab(spec);

tabhostsetCurrentTab(2);

这个例子看看,包括三个activity的~~~

回答不容易,希望能帮到您,满意请帮忙采纳一下,谢谢

我想的结构是 在mainxml中 include tabhostxml, 然后在tabhostxml include 每一个tab的xml 比如: tab1xml, tab2xml, tab3xml如果规范的代码是不是一个 layout 对应一个 javaclass呢?

这个反正都在一个进程里面,广播啊ipc什么的没必要了。是tabhost的话子activity没有直接交互,那么用全局变量吧,把东西存在内存里面。你可以弄一个单例类,里面专门放相关信息,然后每个activity的onResume里面(就是切换到他们的时候)就查看某个变量值了。呃,需要具体例子什么的么大概就是class MsgCenter{private static MsgCenter instance = null;private String msg;private MsgCenter(){}public static getInstance(){ if( instance == null){ instance = new MsgCenter();}return instance;}public void setMsg(String msg){ thismsg = msg;}public String getMsg(){return msg;}}在你的mainactivity里面,如果需要换子activity的话,就MsgCentergetInstance()setMsg("xxx");每个子activity里面onResume里面就String msg=MsgCentergetInstance()getMsg();然后判断msg内如来改变UI了代码是手打的啊,不一定正确。

以上就是关于安卓开发怎么使用tabhost控件全部的内容,包括:安卓开发怎么使用tabhost控件、安卓新手求助!tabhost问题、如何在某一个activity上 *** 作其他activity上的UI的变化等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9340790.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-27
下一篇 2023-04-27

发表评论

登录后才能评论

评论列表(0条)

保存