我設置我的標籤如下:Android的標籤不帶圖標
spec = tabHost.newTabSpec("tab1").setIndicator("Tab 1").setContent(intent);
tabHost.addTab(spec);
現在我有沒有圖標,只有一個標題的選項卡,但它只是留下一個圖標大小的空白與底部的標題 - 我試着在xml中調整layout_height,但是文本消失了,因爲它被渲染到截斷點以下。
如何更改選項卡的大小,並使標題顯示爲不帶圖標?
我設置我的標籤如下:Android的標籤不帶圖標
spec = tabHost.newTabSpec("tab1").setIndicator("Tab 1").setContent(intent);
tabHost.addTab(spec);
現在我有沒有圖標,只有一個標題的選項卡,但它只是留下一個圖標大小的空白與底部的標題 - 我試着在xml中調整layout_height,但是文本消失了,因爲它被渲染到截斷點以下。
如何更改選項卡的大小,並使標題顯示爲不帶圖標?
答案很簡單:你不行。默認的android選項卡將始終爲圖像留出一些空白區域。 但是,您可以創建自己的選項卡來彌補默認選項卡中的「限制」。這是一個非常好的教程來創建自定義選項卡。
http://joshclemm.com/blog/?p=136
祝你好運, Arkde
雅!非常好的工作 - 必須改變XML中的標籤方向,並閱讀評論意見,瞭解如何添加意圖。 謝謝Arkde! – GideonKain
變化,從佈局和顯示按以下代碼片段
tabhost=getTabHost();
intent = new Intent(this,MainActivity.class);
spec1 = tabhost.newTabSpec("").setIndicator("main_tab");
spec1.setContent(intent);
tabhost.addTab(spec1);
intent = new Intent(this,xyz.class);
spec2 = tabhost.newTabSpec("").setIndicator("first_tab");
spec2.setContent(intent);
tabhost.addTab(spec2);
我做到了這一點,這就是爲什麼它出現在底部沒有圖標和標題的大灰盒子 - Arkde的解決方案似乎是正確的解決方法 – GideonKain
改變TabWidget layout_height和重力只有標籤瓷磚寫代碼的tabhost大小在xml中爲我工作。文本不在標籤的中間,而是像以前一樣沿着底部對齊。
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="40dp"
android:gravity="bottom" />
// Center text displayed on a first tab
View view = _tabHost.getTabWidget().getChildAt(0);
if (view != null) {
// Hide icon
View tabImage = view.findViewById(android.R.id.icon);
if (tabImage != null) {
tabImage.setVisibility(View.GONE);
}
// Find text
TextView tabTitle = (TextView) view.findViewById(android.R.id.title);
if (tabTitle != null) {
// Change text gravity
tabTitle.setGravity(Gravity.CENTER);
// Remove text view from it's parent and re-add back to reset layout parameters
ViewGroup parent = (ViewGroup) tabTitle.getParent();
parent.removeView(tabTitle);
parent.addView(tabTitle);
// New default layout parameters will have height set to WRAP_CONTENT, change it to MATCH_PARENT
ViewGroup.LayoutParams params = tabTitle.getLayoutParams();
params.height = ViewGroup.LayoutParams.MATCH_PARENT;
}
}
[無圖標選項卡]的可能重複(http://stackoverflow.com/questions/4460806/tabs-without-icon) –