首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Tab : Android Tab Group和Tabs的定制

Tab : Android Tab Group和Tabs的定制
EN

Stack Overflow用户
提问于 2012-07-02 20:10:17
回答 2查看 5.8K关注 0票数 0

我已经使用Objective在iOS上构建了一个选项卡条,并试图让Android上的选项卡看起来尽可能接近钛。我想知道:

  1. 如何为制表符本身提供背景图像?我唯一能做的就是给它一个背景色。backgroundImage属性没有任何效果。
  2. 如何更改所选选项卡的背景色?我尝试过改变activeTabBackgroundSelectedColor,但没有运气。
  3. 如何修改活动选项卡的图标?我喜欢的图标是灰色时,没有选择,但白色时,选择。我试过创建一个可绘制的,但我无法让安卓应用程序识别它使用Titanium.App.Android.R.drawable.ic_tab_coupon,谢谢你的帮助!

-

不管它有什么价值,下面是我正在使用的代码片段。注意,我还有其他选项卡是以同样的方式实例化/添加的,只是我还没有向它们展示简洁性。

代码语言:javascript
运行
复制
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);
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 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时,当选项卡被选中时,您将无法更改选项卡的图标。

票数 0
EN

Stack Overflow用户

发布于 2012-07-05 18:03:40

1.您需要定义TabWidgetandroid:background属性。例如:

代码语言:javascript
运行
复制
<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的选项卡布局:

代码语言:javascript
运行
复制
<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设置为根布局的背景和选项卡包含的其他元素的背景(在上面的示例中为ImageViewTextView )。

然后膨胀这个布局,并将其设置为选项卡指示器:

代码语言:javascript
运行
复制
    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一样),或者为每个选项卡定义单独的布局。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11300488

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档