【问题标题】:How to Create tabs like Twitter or Instagram to work on all Android platforms > 2.2如何创建 Twitter 或 Instagram 等标签以在所有 Android 平台上工作 > 2.2
【发布时间】:2012-09-04 13:03:46
【问题描述】:

我在这里读过一些文章 How to create Android tabs like this (screenshot)?

后来在 cmets 中出现了 sherlock 库,它为搭载 Android 2.2 的设备带来了 4.0 外观。

我的问题是,我试图让“丑陋”:) 旧的外观可以在新设备上工作。

图片上的东西:

所以我想要有选项卡,没有操作栏,只有 5 个带有图像和文本的框,最好来自字符串,因为它需要本地化。

所以,我正在使用,并且在 tablayout.xml 中我确实设置了标题(来自字符串), 并以编程方式从我的资源中将图像添加到某些选项卡。

th.setup();
    TabSpec specs = th.newTabSpec("tag1");
    //specs.setContent(new Intent(this,MyAppTab.class));
    specs.setContent(R.id.tab1);
    specs.setIndicator(getResources().getString(R.string.tab_myapp_title), getResources().getDrawable(R.drawable.ic_tab1_active));

现在发生的事情是在我的 Android 2.2 上。手机,它看起来很丑,但有图像,有点像我想要的,在妻子的 4.0 上,我看到只有文字的花哨的新标签。

如何添加标签图像以在所有 Android 版本中工作?

Tnx

【问题讨论】:

    标签: android tabs compatibility


    【解决方案1】:

    您可以将自定义视图用作带有this method 的标签指示器。

    1. 膨胀自定义视图
      • View yourView = inflater.inflate(R.layout.my_tab_indicator, null);
    2. 填充它
      • ((ImageView) yourView.findViewById(R.id.tab_indicator_icon)).setBitmapRessource(...)
      • ((TextView) yourView.findViewById(R.id.tab_indicator_title)).setText(...)
    3. 致电tabSpec.setIndicator(yourView);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-29
      • 2017-01-03
      • 1970-01-01
      • 1970-01-01
      • 2013-04-30
      • 1970-01-01
      相关资源
      最近更新 更多