
И не получается сделать чтобы при выделении как в вкладке видео бекграунд полностью заполнял вкладку . Получается вот так

Код tab_host.xml
Код: Выделить всё
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TabHost
android:id="@android:id/tabhost"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/background_tab_widget" >
</TabWidget>
</HorizontalScrollView>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<fragment
android:id="@+id/fAlbum"
android:name="com.musicplayer.app.AlbumFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<fragment
android:id="@+id/fArtist"
android:name="com.musicplayer.app.ArtistFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<fragment
android:id="@+id/fGenre"
android:name="com.musicplayer.app.GenreFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<fragment
android:id="@+id/fVideo"
android:name="com.musicplayer.app.VideoFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<fragment
android:id="@+id/fTrack"
android:name="com.musicplayer.app.TrackFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<fragment
android:id="@+id/fFolder"
android:name="com.musicplayer.app.FolderFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<fragment
android:id="@+id/fPlaylist"
android:name="com.musicplayer.app.PlaylistFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
Код: Выделить всё
public class TabHostActivity extends FragmentActivity {
private static final String TAB_ALBUM = "tab_albums";
private static final String TAB_ARTIST = "tab_artist";
private static final String TAB_GENRE = "tab_genre";
private static final String TAB_FOLDER = "tab_folder";
private static final String TAB_PLAYLIST = "tab_playlist";
private static final String TAB_VIDEO = "tab_video";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.tab_host);
final TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup();
Resources res = getResources();
TabHost.TabSpec tabSpec;
tabSpec = tabHost.newTabSpec(TAB_ALBUM);
tabSpec.setIndicator("", res.getDrawable(R.drawable.tab_icon_albums2));
tabSpec.setContent(R.id.fAlbum);
tabHost.addTab(tabSpec);
tabSpec = tabHost.newTabSpec(TAB_ARTIST);
tabSpec.setIndicator("", res.getDrawable(R.drawable.tab_icon_artists));
tabSpec.setContent(R.id.fArtist);
tabHost.addTab(tabSpec);
tabSpec = tabHost.newTabSpec(TAB_GENRE);
tabSpec.setIndicator("",
res.getDrawable(R.drawable.tab_icon_genre_selector));
tabSpec.setContent(R.id.fGenre);
tabHost.addTab(tabSpec);
tabSpec = tabHost.newTabSpec(TAB_VIDEO);
tabSpec.setIndicator("",
res.getDrawable(R.drawable.tab_icon_video_pressed));
tabSpec.setContent(R.id.fVideo);
tabHost.addTab(tabSpec);
tabSpec = tabHost.newTabSpec(TAB_PLAYLIST);
tabSpec.setIndicator("",
res.getDrawable(R.drawable.tab_icon_track_selector));
tabSpec.setContent(R.id.fTrack);
tabHost.addTab(tabSpec);
tabSpec = tabHost.newTabSpec(TAB_PLAYLIST);
tabSpec.setIndicator("",
res.getDrawable(R.drawable.tab_icon_playlist_selector));
tabSpec.setContent(R.id.fPlaylist);
tabHost.addTab(tabSpec);
tabSpec = tabHost.newTabSpec(TAB_FOLDER);
tabSpec.setIndicator("", res.getDrawable(R.drawable.tab_icon_folders));
tabSpec.setContent(R.id.fFolder);
tabHost.addTab(tabSpec);
tabHost.setCurrentTabByTag(TAB_ALBUM);
setTabBackground(tabHost, this);
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
public void onTabChanged(String tabId) {
setTabBackground(tabHost, getBaseContext());
}
});
}
public static void setTabBackground(TabHost tabhost, Context c) {
for (int i = 0; i < tabhost.getTabWidget().getChildCount(); i++) {
tabhost.getTabWidget().getChildAt(i).setBackgroundResource(0); // unselected
}
}