[英]Creating custom tabhost like in chrome browser for Android
我想為瀏覽器創建自定義tabhost,如標簽。 我很困惑如何將它應用於像Chrome瀏覽器選項卡中的布局,就像在圖像中一樣。
這是我嘗試過的。 我想知道如何用圖像中的斜率創建邊緣。
tab_selected.xml
<item>
<shape android:shape="rectangle" >
<solid android:color="#DCDCDC" />
<corners
android:topLeftRadius="5dp"
android:topRightRadius="5dp" />
</shape>
</item>
<item
android:bottom="2dp"
android:left="1dp"
android:right="1dp"
android:top="1dp">
<shape android:shape="rectangle" >
<solid android:color="#DCDCDC" />
<corners
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
</shape>
</item>
tab_unselected.xml
<item android:top="10dp">
<shape android:shape="rectangle" >
<solid android:color="#AAAAAA" />
</shape>
</item>
<item android:bottom="2dp">
<shape android:shape="rectangle" >
<solid android:color="#AAAAAA" />
<corners
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
</shape>
</item>
我希望可以使用XML中的Pathshape來完成。 任何人都可以指出我的參考? 無法在PathShape上找到引用
把你的頁面放在FrameLayout中,還有一個hashmap(帶有特定的名字)。 然后你可以像這樣改變標簽
FrameLayout fl =new FrameLayout(context);
HashMap<String,LinearLayout> tabs =new HashMap<String,LinearLayout>();
LinearLayout tab =new LinearLayout(context);
fl.addView(tab);
tabs.put("home",tab);
tab =new LinearLayout(context);
fl.addView(tab);
tabs.put("events",tab);
private void changeTab(String tabKey) {
for (java.util.Map.Entry<String, LinearLayout> e : tabs.entrySet()) {
if (e.getKey().compareTo(key) == 0) {
e.getValue().setVisibility(View.VISIBLE);
} else {
e.getValue().setVisibility(View.INVISIBLE);
}
}
}
use this to change tab:
changeTab("home");
注意:您必須將fl設置為活動的內容視圖,或將其添加到另一個視圖並將其設置為contentview
它有兩個九個補丁圖像正常工作。 一個用於活動選項卡,一個用於非活動選項卡
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.