我希望我的選項卡在圖像中以小三角形的形式顯示,如果可以,請使用代碼或文檔幫助我。使用下面的小三角設置選定的選項卡
5
A
回答
11
我認爲,以下方法是最簡單的一個。你只需要安裝以下繪製(實際上,它是標籤Android的默認繪製)作爲標籤的背景:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected" />
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_focus" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_focus" />
<!-- Pressed -->
<item android:state_pressed="true" android:drawable="@drawable/tab_press" />
</selector>
其中tab_press
,tab_focus
和tab_selected
繪項目將是巴新(我寧願9-patches)與向下箭頭和靠近它的透明區域。 tab_unselected
drawable不會有這個箭頭,但仍然會有相同的透明區域。剩下的唯一事情就是爲您的TabWidget
指定負底部餘量。它的值由箭頭的高度決定(不要忘記使用density independent單位):
-2
您可以將圖片與標籤佈局:
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="0dip" />
<FrameLayout
android:fadingEdge="none"
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_below="@android:id/tabs"
android:layout_alignParentBottom="true"
android:padding="0px" />
<ImageView
....
android:id="@+id/down_arrow_left"/>
<ImageView
....
android:id="@+id/down_arrow_right"/>
</RelativeLayout>
,並在標籤活動添加監聽器:
getTabHost().setOnTabChangedListener(new OnTabChangeListener() {
public void onTabChanged(String tabId) {
if (tabId.equels("left")){
findViewById(R.id.down_arrow_left).setVisibility(View.VISIBLE);
findViewById(R.id.down_arrow_right).setVisibility(View.INVISIBLE);
} else if (tabId.equels("right")){
findViewById(R.id.down_arrow_left).setVisibility(View.INVISIBLE);
findViewById(R.id.down_arrow_right).setVisibility(View.VISIBLE);
}
}
});
0
tab_0_info.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_menu_yourImg_selected"
android:state_selected="true" />
<item android:drawable="@drawable/ic_menu_yourImg" />
</selector>
private void addTab(int resouceTabId, int drawableId,
Class<? extends ActivityGroup> groupActivityClass)
{
Intent intent = new Intent(this, groupActivityClass);
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + resouceTabId);
View tabIndicator = LayoutInflater.from(this).inflate(
R.layout.tab_indicator, getTabWidget(), false);
TextView title = (TextView) tabIndicator.findViewById(R.id.title);
title.setText(resouceTabId);
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
icon.setImageResource(drawableId);
spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);
}
//addTab(R.string.yourTabTitle, R.drawable.tab_0_info, YourGroup.class);
相關問題
- 1. 設置ROR頁面的cron選項卡
- 2. jQuery UI選項卡:將選項卡設置爲整頁大小
- 3. ActionBar選項卡「鎖定」下面的ActionBar
- 4. Jquery UI選項卡 - 選定的選項卡更小的行高 - >最後一個選項卡打破設計
- 5. 設置CSS/JS選項卡的默認選擇選項卡
- 6. 設置一定的選項卡上的自定義選項卡的jQuery
- 7. 設置角度下拉的選定值
- 8. 在Emacs中設置選項卡大小
- 9. 如何設置選項卡2在啓動選項卡頁面設置爲默認選項卡
- 10. 添加選項卡與選定的假但選項卡設置顏色tabSelectedTextColor
- 11. 設置選項卡的下角,拐角半徑的標籤導航
- 12. jQuery UI選項卡 - IE中的圓角選項卡角落
- 13. 如何設置選項卡容器中的活動選項卡而不使用選項卡的索引?
- 14. 使用GeoPlugin設置選定選項
- 15. 如何在不保留選項卡的選項卡之外設置根頁面?
- 16. UIB選項卡 - 設置第二個選項卡是活動的
- 17. jQuery選項卡和AJAX:如何設置選項卡的樣式?
- 18. 設置選項卡瀏覽器上新選項卡的焦點
- 19. 設置的單選按鈕下多個選項卡檢查
- 20. 使用按鈕而不是選項卡設置jquery選項卡的Cookie
- 21. jquery選項卡如何使用tabname使用select來設置默認選項卡:
- 22. 爲選項卡式頁面選項卡文本設置自定義字體大小
- 23. 使用jQuery UI選項卡,無法將選項卡位置設置爲絕對
- 24. jQuery的標籤 - 打開我有jQuery UI的選項卡下面的設置選項卡
- 25. iPhone的TabBarController - 以編程方式設置選定的選項卡
- 26. 無法使用角度js代碼設置選擇的選項?
- 27. 如何設置選項卡
- 28. 設置默認選項卡
- 29. 設置選項卡索引
- 30. JQuery選項卡 - 使選定的選項卡可點擊
這就是幫一個小bit.just粗糙地緣ABOT – 2012-03-03 06:17:19
查看我添加的圖片。它應該澄清我的建議。 – 2012-03-03 10:14:39
真的很棒的答案。 – Akram 2012-03-03 10:46:11