本文介绍了安卓:状态自定义选项卡:我如何做一个选择器的可绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! 我知道如何把每个选项卡上的图标,这是没有问题的。我也碰到了这一点:[堆栈溢出的pretty的多少同样的事情线索] [1]I know how to put the icon on each tab, that is no problem. I also ran across this :[Stack Overflow thread on pretty much same thing][1]我也跟着从这个问题的环节之一,并发现[这] [2]I followed one of the links from that question, and found [this][2] pretty的多,这表示使用的XML定义的选择,当然,这样做。但没有相关的瓦特/它让我不知道怎么去选择函数作为绘制这样我就可以用它作为标签的图标标识。也许我会对此错误的方法。但是,这是我应得的,显然缺少的东西。Pretty much, it said use a selector defined in the xml, sure, did that. But there is no id associated w/ it so I am not sure how to get the selector function as a drawable so I can use it as the icon for the tabs. Maybe I am going about this the wrong way.. But this is what I have, and obviously missing something.<selector android:id="@+id/myselector" xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Non focused states --> <item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/darklogo" /> <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/lightlogo" /> <!-- Focused states --> <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/lightlogo" /> <item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/lightlogo" /> <!-- Pressed --> <item android:state_pressed="true" android:drawable="@drawable/lightlogo" /></selector>在我的code,使用生成选项卡:In my code, an example tab is generated using : host.addTab(host.newTabSpec("three") .setIndicator("map",drawables) .setContent(new Intent(this, Map.class)));现在可绘制只是一个参考到绘制的图像资源。如何让我选择一个绘制?Right now drawables is just a reference to an drawable image resource. How do I make the selector a drawable?这是我的问题[1]:更新Android的标签图标 [2]:http://groups.google.com/group/android-evelopers/browse_thread/thread/ef3bdebcb715b385This is my question [1]: Updating Android Tab Icons [2]: http://groups.google.com/group/android-evelopers/browse_thread/thread/ef3bdebcb715b385推荐答案你在这里所包含的XML是定义绘制,可以让你嵌入一个case语句的一种方式。它presents不同的绘制取决于它被分配到视图状态。作为被拉伸,你应该将其保存为水库内一个XML文件/绘制项目的文件夹(例如 tabselector.xml )。The XML you've included here is a way of defining a drawable that lets you embed a case statement. It presents a different drawable depending on the state of the View it's being assigned to. As a drawable, you should save it as an xml file within the res/drawable folder of your project (for example tabselector.xml).要使用它的Tabhost,你需要构造TabActivity,你通常会(如本的教程例子)。To use it for the Tabhost, you need to construct the TabActivity as you normally would (as shown in this tutorial example).然后,当你添加的每个选项卡主机,可以指定 tabselector 绘制的指标如图所示为选项卡1的。Then when you add each tab to the host, you specify the tabselector drawable as the indicator as shown for "TAB 1" below.Drawable mySelector = getResources().getDrawable(R.drawable.tabselector);mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1", mySelector).setContent(R.id.textview1));mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(R.id.textview2));请注意:你的不能的在这一点上更改图标背后的标签背景的颜色Note: You cannot change the color of the tab backgrounds behind the icons at this point. 这篇关于安卓:状态自定义选项卡:我如何做一个选择器的可绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-06 20:02