我在iOS上使用Objective-C构建了一个标签栏,我试图让Android上的标签栏看起来尽可能使用Titanium。我想知道:
如何为标签栏本身提供背景图像?我唯一能做的就是给它一个背景色。 backgroundImage
属性无效。
如何更改所选标签的背景颜色?我已经尝试过改变activeTabBackgroundSelectedColor
而没有运气。
如何修改活动标签的图标?我希望图标在未选中时为灰色,但在选中时为白色。我尝试过创建一个drawable但是我无法让Android应用程序使用Titanium.App.Android.R.drawable.ic_tab_coupon
来识别它
谢谢你的帮助!
-
P.S。对于它的价值,这里是我正在使用的代码片段。请注意,我有其他标签以相同的方式实例化/添加,我只是为了简洁而没有显示它们。
var self = Ti.UI.createTabGroup({
backgroundColor: 'red',
activeTabBackgroundColor: 'blue',
});
var win1 = new Window(L('SpintoWin'));
var tab1 = Ti.UI.createTab({
backgroundColor: 'none',
title: L('SpintoWin'),
icon: '/images/tab-icon-gift.png',
window: win1
});
win1.containingTab = tab1;
self.addTab(tab1);
答案 0 :(得分:0)
1。您需要定义TabWidget
的{{1}}属性。例如:
android:background
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@android:id/tabs" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@drawable/tab_backgrnd" />
</RelativeLayout>
可以是drawable。
2&amp; 3。首先,您可以像Android一样定义选项卡的布局。以下是Android的标签布局:
tab_backgrnd
您可以在此布局中添加任何内容,而不只是一个<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dip"
android:layout_height="64dip"
android:layout_weight="1"
android:layout_marginLeft="-3dip"
android:layout_marginRight="-3dip"
android:orientation="vertical"
android:background="@drawable/tab_indicator">
<ImageView android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
style="?android:attr/tabWidgetStyle" />
</RelativeLayout>
和一个ImageView
。要在按下/选中时更改标签,请将StateListDrawable
设置为根布局的背景和其他元素的背景,该标签包含示例中的TextView
和ImageView
上文)。
然后你膨胀这个布局并将其设置为标签指示符:
TextView
您可以通过编程方式设置每个标签的图标和文字(因为Android确实使用了 TabHost tabHost = getTabHost();
TabHost.TabSpec tabSpec; // Reusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
View tabView;
LayoutInflater inflater = getLayoutInflater();
intent = new Intent().setClass(this, YourActivity1.class);
tabView = inflater.inflate(R.layout.tab_layout, tabHost.getTabWidget(), false);
tabSpec = tabHost.newTabSpec(TAG_TAB_1).setIndicator(tabView).setContent(intent);
tabHost.addTab(tabSpec);
// Do the same for the other tabs
...
和android:id="@+id/icon"
ID),或者您可以为每个标签定义单独的布局。
答案 1 :(得分:0)
这是一个较旧的问题,但我想我会提供一些有关此问题的其他详细信息,因为这些条款的搜索引擎结果中的问题相当高。
http://developer.appcelerator.com/question/53851/android-tab-icon-states
在Titanium 1.7中修改了标签以支持可绘制资源以实现此目的(见下文,包括示例代码)
https://jira.appcelerator.org/browse/TIMOB-3179
现在,在此之后的某个地方修复了指定可绘制资源的功能,因为删除了选项卡的图标。
下一个合乎逻辑的步骤是尝试修改标签获得或失去焦点时的.icon
属性,如以下问题所述:
http://developer.appcelerator.com/question/135063/how-to-change-active-tab-icon
由于原生Android代码采用可绘制资源而非字符串值,因此标签上的图标在绘制后无法更新:
https://jira.appcelerator.org/browse/TIMOB-9962
所以,问题的答案是:
在使用Ti.UI.TabGroup / Ti.UI.Tab时,如果选择了以上某个选项,则无法更改选项卡的图标。