gpt4 book ai didi

Android TabHost 选项卡背景高度较小

转载 作者:太空狗 更新时间:2023-10-29 16:42:21 26 4
gpt4 key购买 nike

我在使用选项卡设置设计时遇到问题。因此,我为添加到 tabHost 中的每个 tabspec 创建了选择器。这是它的样子:

enter image description here

这是我的标签页 Activity :

public class TabLayouts extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabhost);

TabHost tabHost = getTabHost();
tabHost.getTabWidget().setStripEnabled(false);

TabSpec latest = tabHost.newTabSpec(getString(R.string.latest_title));
tabHost.setBackgroundResource(R.drawable.tabbar);

// setting Title and Icon for the Tab
latest.setIndicator(getString(R.string.latest_title), getResources().getDrawable(R.drawable.latest_albums_sel));
Intent latestAlbums = new Intent(this, LatestAlbums.class);
latest.setContent(latestAlbums);

TabSpec favorites = tabHost.newTabSpec(getString(R.string.favorites_title));
favorites.setIndicator(getString(R.string.favorites_title), getResources().getDrawable(R.drawable.favorites_sel));
Intent favoritesInt = new Intent(this, Favorites.class);
favorites.setContent(favoritesInt);

TabSpec downloaded = tabHost.newTabSpec(getString(R.string.downloaded_title));
downloaded.setIndicator(getString(R.string.downloaded_title), getResources().getDrawable(R.drawable.downloaded_sel));
Intent downloadedIntent = new Intent(this, Downloaded.class);
downloaded.setContent(downloadedIntent);

tabHost.addTab(latest);
tabHost.addTab(favorites);
tabHost.addTab(downloaded);
}
}

还有我的一个选择器:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- PRESSED TAB -->
<item android:top="0dp" android:left="0dp" android:right="0dp" android:bottom="0dp"
android:state_pressed="true"
android:drawable="@drawable/menu3_pr"
/>
<!-- INACTIVE TABS -->
<item android:top="0dp" android:left="0dp" android:right="0dp" android:bottom="0dp"
android:state_selected="false"
android:state_focused="false"
android:state_pressed="false"
android:drawable="@drawable/menu3_nr"
/>
<!-- ACTIVE TAB -->
<item android:top="0dp" android:left="0dp" android:right="0dp" android:bottom="0dp"
android:state_selected="true"
android:state_focused="false"
android:state_pressed="false"
android:drawable="@drawable/menu3_pr"
/>
<!-- SELECTED TAB -->
<item android:top="0dp" android:left="0dp" android:right="0dp" android:bottom="0dp"
android:state_focused="true"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/menu3_pr"
/>
</selector>

还有我的 tabhost 布局:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:background="@drawable/tabbar"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:background="@drawable/background"
android:layout_above="@android:id/tabs"
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="match_parent"/>
<TabWidget
android:showDividers="none"
android:layout_alignParentBottom="true"
android:id="@android:id/tabs"
android:scaleY="0.8"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
</TabHost>

谁能帮我解决这个问题?

最佳答案

这是一种简单的技术,您应该使用 .setIndicator() 并传递一个参数,即

latest.setIndicator(getString(R.string.latest_title)). 

上面你正在使用

.setIndicator(getString(R.string.latest_title), getResources().getDrawable(R.drawable.latest_albums_sel))

现在删除第二个参数

getResources().getDrawable(R.drawable.latest_albums_sel)

从您的代码以及何时添加所有标签,例如

tabHost.addTab(latest);
tabHost.addTab(favorites);
tabHost.addTab(downloaded);

使用下面的代码

tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.latest);
tabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.favorites);
tabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.downloaded);

你就完成了:)这对我有所帮助,希望您也能解决您的问题。

关于Android TabHost 选项卡背景高度较小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15708519/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com