我已经使用Objective在iOS上构建了一个选项卡条,并试图让Android上的选项卡看起来尽可能接近钛。我想知道:
backgroundImage属性没有任何效果。activeTabBackgroundSelectedColor,但没有运气。Titanium.App.Android.R.drawable.ic_tab_coupon,谢谢你的帮助!-
不管它有什么价值,下面是我正在使用的代码片段。注意,我还有其他选项卡是以同样的方式实例化/添加的,只是我还没有向它们展示简洁性。
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);发布于 2013-02-15 21:20:04
这是一个较老的问题,但我想我会提供一些额外的细节,因为这个问题是相当高的搜索引擎结果的术语。
http://developer.appcelerator.com/question/53851/android-tab-icon-states
在钛中,对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时,当选项卡被选中时,您将无法更改选项卡的图标。
发布于 2012-07-05 18:03:40
1.您需要定义TabWidget的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>其中tab_backgrnd可能是任何可绘制的。
2 & 3.首先定义选项卡的布局,就像Android本身一样。以下是Android的选项卡布局:
<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和一个TextView。若要在按下/选择选项卡时更改选项卡,请将StateListDrawable设置为根布局的背景和选项卡包含的其他元素的背景(在上面的示例中为ImageView和TextView )。
然后膨胀这个布局,并将其设置为选项卡指示器:
    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使用android:id="@+id/icon"和android:id="@+id/title" ids一样),或者为每个选项卡定义单独的布局。
https://stackoverflow.com/questions/11300488
复制相似问题