【问题标题】:How to set TabHost title name in two lines如何在两行中设置 TabHost 标题名称
【发布时间】:2014-01-30 13:48:06
【问题描述】:

我需要将 tabhost 的 Title 设置为两行。 当我选择选项卡时,我将全文作为自动滚动的东西查看,但我需要它以两行显示,以便它始终可以完全查看。有人可以帮忙吗!

public class Tabs extends Activity implements OnClickListener {
TabHost th;


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tabs);
    th = (TabHost) findViewById(R.id.tabhost);



    th.setup();
    TabSpec specs = th.newTabSpec("tag1");
    specs.setContent(R.id.tab1);
    specs.setIndicator("Large Text");

//That is i need to put "Large" in one line and "Text" in next line in the title of the tabhost     

    th.addTab(specs);

    specs = th.newTabSpec("tag2");
    specs.setContent(R.id.tab2);
    specs.setIndicator("Small");
    th.addTab(specs);

    specs = th.newTabSpec("tag3");
    specs.setContent(R.id.tab3);
    specs.setIndicator("TEXT");
    th.addTab(specs);

    specs = th.newTabSpec("tag4");
    specs.setContent(R.id.tab4);
    specs.setIndicator("TXET");
    th.addTab(specs);

}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

}

}

【问题讨论】:

    标签: android android-tabhost android-tabs


    【解决方案1】:

    首先,我会告诉你,我不鼓励将长文本设置为选项卡名称。标签标题旨在提供简短易懂的描述,将您的名称设置为长文本可能会使您的用户复杂化。

    也就是说,一种方法是定义一个新布局,您将在其中实现两个单独的TextViews,或者仅将其maxLines 属性设置为2。这样,您可以通过以下方式简单地 inflate 您的标签:

    final View view = LayoutInflater.from(context).inflate(R.layout.your_new_tab_layout, null);
    TextView tv1 = view.findViewById(R.id.your_first_line_textview);
    TextView tv2 = view.findViewById(R.id.your_second_line_textview);
    tv1.setText("My first line");
    tv2.setText("My second line");
    

    或者,使用第二种方法:

    final View view = LayoutInflater.from(context).inflate(R.layout.your_new_tab_layout, null);
    TextView tv = view.findViewById(R.id.your_double_line_textview);
    tv.setText("First line\nSecond line);
    

    【讨论】:

      猜你喜欢
      • 2020-11-23
      • 2012-12-06
      • 1970-01-01
      • 2020-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-07
      • 2013-09-01
      相关资源
      最近更新 更多