我想在选项卡上设置图标。我的代码是正确的,我确信。这是因为安卓版本的问题吗?我看了很多代码,但都是一样的。代码为:;
package com.mesutemre.androidtabkullanimi;
import android.os.Bundle;
import android.app.Activity;
import android.app.ActivityGroup;
import android.app.TabActivity;
import android.content.Intent;
import android.view.Menu;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class MainActivity extends TabActivity {
@SuppressWarnings("deprecation")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabhost = getTabHost();
tabhost.setup();
tabhost.addTab(tabhost
.newTabSpec("tabindis1")
.setIndicator("SEKME1",
getResources().getDrawable(R.drawable.document))
.setContent(new Intent(MainActivity.this, Sekme1Activity.class)));
tabhost.addTab(tabhost
.newTabSpec("tabindis2")
.setIndicator("SEKME2",
getResources().getDrawable(R.drawable.music))
.setContent(new Intent(MainActivity.this, Sekme1Activity.class)));
tabhost.addTab(tabhost
.newTabSpec("tabindis3")
.setIndicator("SEKME3",
getResources().getDrawable(R.drawable.delete))
.setContent(new Intent(MainActivity.this, Sekme1Activity.class)));
tabhost.addTab(tabhost
.newTabSpec("tabindis4")
.setIndicator("SEKME4",
getResources().getDrawable(R.drawable.close))
.setContent(new Intent(MainActivity.this, Sekme1Activity.class)));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
我从一些链接中读到,这是一个问题adroid4.0和更高版本。我能为选项卡上的设置图标做些什么。
请尝试setView来设置TextView,而不是setIndicator。将图标和指示器文本设置为TextView。