默认情况下不想突出显示选项卡
我有一个带有图像和列表视图的布局。在它们下面我需要添加选项卡。 当我使用选项卡小部件时,它会突出显示第一个选项卡,并在选项卡下方显示该选项卡活动结果。 所以我必须停止第一个选项卡的活动。单击选项卡时,仅应调用该活动,并且应转到另一个屏幕。
下面是我的 xml 代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView android:id="@+id/imageView1"
android:background="@drawable/banner"
android:layout_width="323dp"
android:layout_height="100dp"></ImageView>
<RelativeLayout android:id="@+id/relativeLayout1" android:layout_height="28dp" android:layout_width="fill_parent">
<ImageView android:layout_alignParentTop="true" android:onClick="mapfunction" android:layout_width="wrap_content" android:id="@+id/imageView2" android:src="@drawable/map1" android:layout_height="100dp" android:layout_marginRight="10dp" android:layout_toLeftOf="@+id/textView1"></ImageView>
<ImageView android:layout_width="wrap_content" android:id="@+id/imageView3" android:src="@drawable/listtab" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginRight="10dp" android:layout_toLeftOf="@+id/textView2"></ImageView>
<TextView android:id="@+id/textView2" android:text="LIST" android:layout_width="wrap_content" android:textStyle="bold" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toLeftOf="@+id/imageView2" android:layout_marginRight="14dp"></TextView>
<TextView android:id="@+id/textView1" android:text="MAP" android:layout_width="wrap_content" android:textStyle="bold" android:layout_height="wrap_content" android:layout_alignBottom="@+id/imageView3" android:layout_alignParentRight="true" android:layout_marginRight="31dp"></TextView>
</RelativeLayout>
<ListView android:id="@id/ListView01" android:layout_width="fill_parent" android:layout_height="253dp"></ListView>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent" android:layout_height="44dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="34dp"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:padding="5dp" android:layout_height="fill_parent"/>
</TabHost>
</LinearLayout>
下面是我用于显示选项卡的活动代码。
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
intent = new Intent().setClass(this, Contacts.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("places").setIndicator("PLACES",
res.getDrawable(R.drawable.places))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, Contacts.class);
spec = tabHost.newTabSpec("camera").setIndicator("CAMERA",
res.getDrawable(R.drawable.camera))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
I have a layout with image and listview. Below them i need to add tabs.
When i used tab widget it is highlighted first tab and displaying that tab activity result below the tabs.
So i have to stop the activity of the first tab. When clicking on tab only the activity should be called and it should go to another screen.
Below is my xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView android:id="@+id/imageView1"
android:background="@drawable/banner"
android:layout_width="323dp"
android:layout_height="100dp"></ImageView>
<RelativeLayout android:id="@+id/relativeLayout1" android:layout_height="28dp" android:layout_width="fill_parent">
<ImageView android:layout_alignParentTop="true" android:onClick="mapfunction" android:layout_width="wrap_content" android:id="@+id/imageView2" android:src="@drawable/map1" android:layout_height="100dp" android:layout_marginRight="10dp" android:layout_toLeftOf="@+id/textView1"></ImageView>
<ImageView android:layout_width="wrap_content" android:id="@+id/imageView3" android:src="@drawable/listtab" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginRight="10dp" android:layout_toLeftOf="@+id/textView2"></ImageView>
<TextView android:id="@+id/textView2" android:text="LIST" android:layout_width="wrap_content" android:textStyle="bold" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toLeftOf="@+id/imageView2" android:layout_marginRight="14dp"></TextView>
<TextView android:id="@+id/textView1" android:text="MAP" android:layout_width="wrap_content" android:textStyle="bold" android:layout_height="wrap_content" android:layout_alignBottom="@+id/imageView3" android:layout_alignParentRight="true" android:layout_marginRight="31dp"></TextView>
</RelativeLayout>
<ListView android:id="@id/ListView01" android:layout_width="fill_parent" android:layout_height="253dp"></ListView>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent" android:layout_height="44dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="34dp"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:padding="5dp" android:layout_height="fill_parent"/>
</TabHost>
</LinearLayout>
Below is my activity code for displaying the tabs.
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
intent = new Intent().setClass(this, Contacts.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("places").setIndicator("PLACES",
res.getDrawable(R.drawable.places))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, Contacts.class);
spec = tabHost.newTabSpec("camera").setIndicator("CAMERA",
res.getDrawable(R.drawable.camera))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您不想突出显示当前选项卡,则只需将 2 个图形设置为相同即可。
If you never want the current tab highlighted then you can simply set the 2 graphics the same.
只需不要在活动中设置当前选项卡
tabHost.setCurrentTab(0);
Simply dont set the current tab in your activity
tabHost.setCurrentTab(0);