如何在android中设置片段主机的图标?

时间:2014-01-06 07:51:32

标签: android android-fragments

这是我设置片段标签的活动:

 private FragmentTabHost mTabHost;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.bottom_tabs);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);

    Bundle b = new Bundle();
    b.putString("key", "Simple");
    mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"),this.getResources().getDrawable(R.drawable.iconxml)
            Fragment1.class, b);

iconxml.xml文件

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
 android:state_pressed="false"
 android:drawable="@drawable/ic_launcher" />
<item android:drawable="@drawable/icontab" />

我的应用程序崩溃了.. plz help

![例外] [logcat outout]

3 个答案:

答案 0 :(得分:1)

尝试改变这一点:

  mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple",getResources().getDrawable(R.drawable.iconxml)
        Fragment1.class, b);

答案 1 :(得分:0)

将其替换为

   mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"),this.getResources().getDrawable(R.drawable.iconxml) Fragment1.class, b);

   mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple",this.getResources().getDrawable(R.drawable.iconxml)) Fragment1.class, b);

查看TabHost.TabSpec

答案 2 :(得分:0)

http://wptrafficanalyzer.in/blog/creating-navigation-tabs-using-tabhost-and-fragments-in-android/

我尝试修改上面的例子,最后解决了我的问题:)