以下是我的Tab类。在选择和取消选择时,我正在尝试更改选项卡的背景颜色。如果您尝试使用自己的颜色(我已经完成)自定义选项卡,为什么未选中选项卡下的边框与选定选项卡的颜色相同?让我给你看一张图片:http://tinypic.com/view.php?pic=335e6ae&s=6
在图片的左侧,您可以在模拟器中看到真实的外观。在右边,你有我想要的照片。正如您在模拟器中看到的那样,未选定标签下的边框仍然具有标准灰色?是否可以更改或删除此边框/标签?我怎么改变它?
目前我通过void initTabsAppearance()方法自定义我的选项卡,其中我使用选择器在xml文件中设置背景。没什么特别的或狂热的三色堇...
public class Tabs extends TabActivity
{
private static final String TAG = "TabHostActivity";
private boolean mHaveShownStartDialog = false;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_host);
setOnCreatePreferences();
try
{
addTab(getString(R.string.Search), R.drawable.searchtab, SearchTask.class );
addTab(getString(R.string.Bookmarks), R.drawable.favoritetab, Bookmarks.class );
addTab(getString(R.string.Latest), R.drawable.historytab, Latest.class );
addTab(getString(R.string.QAndA), R.drawable.forumtab, LatestFeedback.class );
getTabHost().setCurrentTab( 0 );
TabWidget widget = getTabHost().getTabWidget();
this.initTabsAppearance(widget);
}
catch(Exception e)
{
Log.e(TAG, e.getMessage());
}
}
private void addTab( CharSequence label, int drawable_id, Class<?> c )
{
TabHost.TabSpec spec = getTabHost().newTabSpec("tab" + " "+ label);
spec.setIndicator( label, getResources().getDrawable( drawable_id ) );
spec.setContent( new Intent().setClass( this, c ) );
getTabHost().addTab( spec );
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate( R.menu.tabs_menu, menu );
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch ( item.getItemId() )
{
case R.id.tabs_menu_options_item:
//startActivityForResult( new Intent( this, Options.class ) , 0 );
return true;
default: return super.onOptionsItemSelected(item);
}
}
private void initTabsAppearance(TabWidget tabWidget){
for(int i=0; i<tabWidget.getChildCount(); i++)
tabWidget.getChildAt(i).setBackgroundResource(R.drawable.tabcolors); //unselected
//((TextView) tabWidget.getChildAt(getTabHost().getCurrentTab())).setTextColor(0xffffffff);
//getTabHost().getTabWidget().getChildAt(getTabHost().getCurrentTab()).setBackgroundColor(Co lor.parseColor("#000000")); //selected
}
private void setOnCreatePreferences()
{
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences( getBaseContext() );
boolean mUseStartDialog = preferences.getBoolean( "use_dialog", true );
if( mUseStartDialog )
{
if( !mHaveShownStartDialog )
{
mHaveShownStartDialog = true;
startActivity( new Intent( this, WelcomeDialog.class ) );
}
}
}
}
tabcolors.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:drawable="@color/tabWhite"/>
<item android:state_pressed="true"
android:drawable="@color/tabBlack"/>
<item android:drawable="@color/tabBlack"/>
</selector>
答案 0 :(得分:1)
它叫做tabStrip。 要删除它,你可以
tabWidget.setStripEnabled(false);
有关如何自定义文档的文档,请访问: http://developer.android.com/reference/android/widget/TabWidget.html#attr_android:tabStripEnabled