我知道onTabChanged方法獲取當前標籤ID。你能指導我獲得標籤的索引嗎?要獲取Android中的標籤索引
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
currentTab = tabId;
updatetab();
}
我知道onTabChanged方法獲取當前標籤ID。你能指導我獲得標籤的索引嗎?要獲取Android中的標籤索引
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
currentTab = tabId;
updatetab();
}
使用本
mytabs.getCurrentTab();
嘗試在呼叫getCurrentTab()
你TabHost
- 我認爲應該這樣做。
如果您使用Tab鍵代替TabHost使用這種結構返回當前選中的標籤:
Tab currentTab = actionBar.getSelectedTab();
從那裏,你可以閱讀或修改。例如,如果要更改活動標籤的文本的顏色,你可以這樣做:
currentTab.setCustomView(R.layout.actionbar_active_tab_layout);
TextView currentTabView = (TextView) currentTab.getCustomView().findViewById(R.id.ActiveTab);
currentTabView.setTextColor(getResources().getColor(R.color.purple));
很顯然,你還需要一個簡單的佈局文件,以及如:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/ActiveTab"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:text="tab name"
android:textColor="@color/Gray"
android:textSize="20sp"
android:textScaleX="1.3"
android:textStyle="bold" />
</LinearLayout>
打我它(但只是)。 :) – Squonk
當人們決定來回答,我們都這樣做,同時我們不XD –
它不工作 \t @覆蓋 \t公共無效onTabChanged(字符串tabId){ \t \t // TODO自動 - 生成方法存根 \t currentTab = tabId; \t Log.i(「NewTicket」,「我目前在標籤索引::」+ th.getCurrentTab()); \t \t updatetab(); E/AndroidRuntime(2511):java.lang.NullPointerException 12-24 23:37:23.949:E/AndroidRuntime(2511) 23:37:23.949:E/AndroidRuntime(2511):\t at com.example.restaurent.NewTicket.onItemClick(NewTicket.java:175) 12-24 23:37:23.949:E/AndroidRuntime(2511):at – user1822729