Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 安卓:can';t在tabhost上显示指示器文本和可绘图_Java_Android_Android Tabhost - Fatal编程技术网

Java 安卓:can';t在tabhost上显示指示器文本和可绘图

Java 安卓:can';t在tabhost上显示指示器文本和可绘图,java,android,android-tabhost,Java,Android,Android Tabhost,我正在尝试在android上用四个标签做一个简单的标签应用。我的问题是,当我想显示图标和指示器时,它只显示文本指示器,我想在tabhost上显示可绘制和指示器文本,这是我的代码: @Override protected void onCreate(Bundle savedInstanceState) { //hide title bar BasicDisplaySettings.toggleTaskBar(SimasCardMainActi

我正在尝试在android上用四个标签做一个简单的标签应用。我的问题是,当我想显示图标和指示器时,它只显示文本指示器,我想在tabhost上显示可绘制和指示器文本,这是我的代码:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        //hide title bar
                BasicDisplaySettings.toggleTaskBar(SimasCardMainActivity.this, false);
                //show status bar
                BasicDisplaySettings.toggleStatusBar(SimasCardMainActivity.this, true);

        super.onCreate(savedInstanceState);
        setContentView(R.layout.simascard);

        Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab

        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this, TerbaruSimasCard.class);
        spec = tabHost.newTabSpec("Terbaru").setIndicator("Terbaru",
                  res.getDrawable(R.drawable.menu_terbaru))
                  .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, MerchantSimasCard.class);
        spec = tabHost.newTabSpec("Merchant").setIndicator("Merchant",
                  res.getDrawable(R.drawable.menu_merchant))
                  .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, TentangSimasCard.class);
        spec = tabHost.newTabSpec("Tentang").setIndicator("Tentang",
                  res.getDrawable(R.drawable.menu_tentang))
                  .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, FaqSimasCard.class);
        spec = tabHost.newTabSpec("FAQ").setIndicator("FAQ",
                  res.getDrawable(R.drawable.menu_faq))
                  .setContent(intent);
        tabHost.addTab(spec);


        for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++){
            tabHost.getTabWidget().getChildAt(i).setPadding(0,0,0,0);
            tabHost.getTabWidget().getChildTabViewAt(i).setBackgroundDrawable(null);
        }
        tabHost.setCurrentTab(0);
    }

//  @Override
    public void onBackPressed() {
     finish();
    }

它将显示一个图标,但当我在
setIndicator
上添加文本时,例如
setIndicator(“Tentang”)
它只在tabhost上显示指示器文本,我不知道我的代码哪里出了问题,我试图增加选项卡高度,但没有效果,我希望有人能帮助我解决我的问题。谢谢

删除此
tabHost.getTabWidget().getChildTabViewAt(i).setBackgroundDrawable(null)

并将其替换为

tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.menu_tentang);
我已经这样做了,它工作得很好

Resources ressources = getResources(); 
    TabHost tabHost = getTabHost();

    Intent addfriend = new Intent().setClass(this, yourclass1.class);
    Intent mailfriend = new Intent().setClass(this, yourclass2.class);
    tabHost.addTab(tabHost.newTabSpec("child1").setIndicator("your tag",getResources().getDrawable(R.drawable.youpng)).setContent(addfriend));
    tabHost.addTab(tabHost.newTabSpec("child1").setIndicator("your tag",getResources().getDrawable(R.drawable.yourpng)).setContent(mailfriend));



    tabHost.getTabWidget().getChildAt(0).setBackgroundColor(getResources().getColor(R.color.anycolor));
    tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.yourpng);

    tabHost.getTabWidget().getChildAt(1).setBackgroundColor(getResources().getColor(R.color.anycolor));
    tabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.youpng);
Resources ressources = getResources(); 
    TabHost tabHost = getTabHost();

    Intent addfriend = new Intent().setClass(this, yourclass1.class);
    Intent mailfriend = new Intent().setClass(this, yourclass2.class);
    tabHost.addTab(tabHost.newTabSpec("child1").setIndicator("your tag",getResources().getDrawable(R.drawable.youpng)).setContent(addfriend));
    tabHost.addTab(tabHost.newTabSpec("child1").setIndicator("your tag",getResources().getDrawable(R.drawable.yourpng)).setContent(mailfriend));



    tabHost.getTabWidget().getChildAt(0).setBackgroundColor(getResources().getColor(R.color.anycolor));
    tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.yourpng);

    tabHost.getTabWidget().getChildAt(1).setBackgroundColor(getResources().getColor(R.color.anycolor));
    tabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.youpng);