0

下面是我的 Tab 类。我正在尝试更改选项卡的背景颜色,当被选中和取消选中时。如果您尝试使用自己的颜色自定义选项卡(我已经这样做了),为什么未选择选项卡下的边框与所选选项卡的颜色不同?让我给你看一张图:http ://tinypic.com/view.php?pic=335e6ae&s=6

图片左侧是模拟器的真实外观。在右边,你有我的 Photoshop 想要的外观。正如您在模拟器中看到的那样,未选中选项卡下的边框仍然具有标准的灰色?是否可以更改或删除此边框/标签?我怎么改呢?

目前,我通过 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>
4

1 回答 1

1

它被称为标签条。要删除它,你可以这样做

tabWidget.setStripEnabled(false);

关于如何自定义它的文档可以在这里找到:http: //developer.android.com/reference/android/widget/TabWidget.html#attr_android :tabStripEnabled

于 2012-09-08T11:25:30.183 回答