我需要以两行设置TABHOST的标题。当我选择选项卡时,我将全文视为可自动滚动的东西,但是我需要以两行显示,以便始终可以完全查看。任何人都可以帮忙!
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
}
}
首先,我告诉你,我劝阻将长文本设置为标签名称。标题标题旨在提供简短易懂的描述,将您的名字设置为长文本可能会使您的用户复杂化。
说,一种方法将定义一个新布局,您将在其中实现两个单独的TextView
s,或者仅将其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 linenSecond line);