Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/235.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 如何在开始时更改tabHost?_Java_Android_Android Studio_Android Tabhost_Android Drawable - Fatal编程技术网

Java 如何在开始时更改tabHost?

Java 如何在开始时更改tabHost?,java,android,android-studio,android-tabhost,android-drawable,Java,Android,Android Studio,Android Tabhost,Android Drawable,当我开始活动时,3个选项卡都是旧的选项卡样式,而不是setBackgroundResource(R.drawable.button) 但新的标签样式只有在选择其中一个标签后才会出现。 下面是我的代码,让我知道如何更改代码,以便3个选项卡可以显示新样式 代码: final TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost); TabHost.TabSpec spec; Intent intent; spec = tabHo

当我开始活动时,3个选项卡都是旧的选项卡样式,而不是setBackgroundResource(R.drawable.button)

但新的标签样式只有在选择其中一个标签后才会出现。 下面是我的代码,让我知道如何更改代码,以便3个选项卡可以显示新样式

代码:

final TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
TabHost.TabSpec spec;
Intent intent;

spec = tabHost.newTabSpec("1");
spec.setIndicator("Inventar 1");
intent = new Intent(this, Spielregeln.class);
spec.setContent(intent);
tabHost.addTab(spec.setIndicator(" ", ResourcesCompat.getDrawable(getResources(), R.drawable.handwerk, null)));

spec = tabHost.newTabSpec("2");
spec.setIndicator("Inventar 2");
intent = new Intent(this, Spielregeln.class);
spec.setContent(intent);
tabHost.addTab(spec.setIndicator(" ", ResourcesCompat.getDrawable(getResources(), R.drawable.freunde, null)));

spec = tabHost.newTabSpec("3");
spec.setIndicator("Inventar 3");
intent = new Intent(this, Spielregeln.class);
spec.setContent(intent);
tabHost.addTab(spec.setIndicator(" ", ResourcesCompat.getDrawable(getResources(), R.drawable.inventar, null)));

tabHost.setCurrentTab(0);

tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
    @Override
    public void onTabChanged(String arg0) {
        for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
            tabHost.getTabWidget().getChildAt(i)
                    .setBackgroundResource(R.drawable.button); // unselected
        }
        tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab())
                .setBackgroundResource(R.drawable.button_clicked); // selected

    }
});
final TabHost TabHost=(TabHost)findviewbyd(android.R.id.TabHost);
TabHost.TabSpec;
意图;
spec=tabHost.newTabSpec(“1”);
规格设定指示器(“发明者1”);
intent=新intent(这个,Spielregeln.class);
规格设置内容(意图);
tabHost.addTab(spec.setIndicator(“,ResourcesCompat.getDrawable(getResources(),R.drawable.handwerk,null));
spec=tabHost.newTabSpec(“2”);
规格设定指示器(“发明者2”);
intent=新intent(这个,Spielregeln.class);
规格设置内容(意图);
tabHost.addTab(spec.setIndicator(“,ResourcesCompat.getDrawable(getResources(),R.drawable.freunde,null));
spec=tabHost.newTabSpec(“3”);
规格设定指示器(“发明者3”);
intent=新intent(这个,Spielregeln.class);
规格设置内容(意图);
tabHost.addTab(spec.setIndicator(“”,ResourcesCompat.getDrawable(getResources(),R.drawable.inventar,null));
tabHost.setCurrentTab(0);
tabHost.setOnTabChangedListener(新tabHost.ontabchangedListener(){
@凌驾
已更改的公共void onTabChanged(字符串arg0){
对于(int i=0;i