我刚刚尝试使用Android,并构建了一个包含带有三个选项卡的TabHost的UI.每个选项卡都由其自己的Activity提供支持.第一个选项卡包含带有预先填充的行集的列表视图,并且是从自定义ArrayAdapter构建的.
我遇到的问题是没有ListView行可以自定义.换句话说,当我点击它们时,没有橙色选择.如果我在我的Nexus One上使用滚动球它会选择,但任何触摸手势似乎都没有响应.
所有UI都使用XML文件处理,其中包含一个包含TabHost - > LinearLayout - > TabWidget/FrameLayout的main.xml和一个包含我的ListView UI的nearby_activity.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">
<TextView
android:id="@+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/nearby_no_events"
/>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1.0"
android:choiceMode="multipleChoice"
android:divider="#d9d9d9"
android:dividerHeight="1px"
android:cacheColorHint="#eee"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我的Activity中的相关代码设置为在选定的选项卡中显示.
public class NearbyActivity extends ListActivity
{
private ArrayList<Event> m_events = null;
private EventAdapter m_adapter = null;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.nearby_activity);
getEvents();
this.m_adapter = new EventAdapter(this, R.layout.eventrow, m_events);
setListAdapter(this.m_adapter);
}
private void getEvents()
{
m_events = new ArrayList<Event>();
for (int i …Run Code Online (Sandbox Code Playgroud) 我已经按照Android选项卡主机的教程,并能够在模拟器上运行.现在我想要做的只是在一个tabview中实现一个文本框和按钮.一旦用户进入文本框并按下按钮,文本框中输入的值就会传递给第二个选项卡,我可以使用该值进行进一步计算.
请指导我怎么做?谢谢,Alok.
我有两个关于TabHost的问题.
我们可以添加最多数量的标签tabHost.addTab(spec)吗?我需要多达10个标签.
我已设法更改每个选项卡和选项卡分隔符的颜色,但我仍然无法更改选项卡下的灰色线的颜色(在每个未选定的选项卡下)).那条线的名称是什么?我可以更改颜色甚至完全删除它吗?
谢谢!
tabWidget中的divider工作正常但是当tab小部件的背景设置为
tabHost.getTabWidget().getChildTabViewAt(tabId).setBackgroundResource(R.drawable.tab_indicator);
Run Code Online (Sandbox Code Playgroud)
问题是如何在设置背景后设置选项卡小部件中的分隔符,虽然我使用过
tabhost.getTabWidget().setDividerDrawable(R.drawable.tab_widget_divider);
Run Code Online (Sandbox Code Playgroud)
是不适用于多个选项卡.
我已经搜索了很长时间了...我正在编写一个应该兼容Android 2.2和Android 4.0的应用程序.由于在Android 4.0 Tabs被弃用,我想知道什么是正确的方法呢?如果我仍然在我的测试中使用Tabs它们看起来相当不错(所有大小相同,没有图标...)但是如果我然后在2.2上运行它们都看起来压在一起(只是每个标签的标题大小,也许与我使用HorizontalScrollView有关?)这里的正确决定是什么?只需使用Android 2.2和4.0的标签?如果是,我怎样才能将2.2上的选项卡设置为相同的大小?使用4.0上的片段和2.2上的选项卡?如果是,我将如何实现这一点?如果我应该使用Tabs我应该只使用4个标签(我有2到10个动态)并添加一个额外的"更多"标签?如果是,我该怎么做?
我希望这个问题是可以理解的.如果没有随意要求更多信息.
我正在学习在android中创建基于Tab的应用程序.在LogCat中,"你必须指定一种创建标签指示器的方法"错误.
继承人的代码......
.java文件......
package com.example.tabdemo;
import android.os.Bundle;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.view.Menu;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
@SuppressWarnings("deprecation")
public class MainActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabhost=getTabHost();
TabHost.TabSpec spec1=tabhost.newTabSpec("Tab 1");
Intent intent1=new Intent(this, Tabone.class);
spec1.setContent(intent1);
// spec1.setIndicator("Tab 1", getResources().getDrawable(R.drawable.face));
spec1.setIndicator("Tab 1");
tabhost.addTab(spec1);
TabHost.TabSpec spec2=tabhost.newTabSpec("Tab 2");
Intent intent2=new Intent(this,Tabtwo.class);
spec2.setContent(intent2);
// spec1.setIndicator("Tab 2", getResources().getDrawable(R.drawable.face));
spec1.setIndicator("Tab 2");
tabhost.addTab(spec2);
tabhost.setCurrentTab(1);
}
}
Run Code Online (Sandbox Code Playgroud)
活动xml文件...
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent" …Run Code Online (Sandbox Code Playgroud) 我已经有这个问题1周了.
我MainActivity extends TabActivity在每个标签中都有A和B两个活动.
现在我想按活动A中的按钮将当前页面设置为活动B的选项卡
但是我不能使用setCurrentTab方法除外MainActivity.如何使此功能起作用?
public class MainActivity extends TabActivity
public TabHost tabHost;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources res = getResources();
tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, StartActivity.class);
spec = tabHost.newTabSpec("tab1").setIndicator("A",res.getDrawable(R.drawable.start))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, WeatherActivity.class);
spec = tabHost.newTabSpec("tab2").setIndicator("B",res.getDrawable(R.drawable.weather))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
Run Code Online (Sandbox Code Playgroud)
public class AActivity extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.a_layout);
Button b = (button)findViewById(R.id.bt);
b.setOnClickListener(this);
}
public …
Run Code Online (Sandbox Code Playgroud) 我搜索了几个小时来找到这个问题的工作解决方案,我设法创建了一个.我希望有人也可以使用这个解决方案.
我正在使用标签主机来显示标签,但即使我只是将其拖放到我的布局上并运行它,它没有显示标签,它显示白色屏幕,我猜这是第一个标签视图的线性布局.
<?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:orientation="vertical" >
<TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
<LinearLayout
android:id="@+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
当我在模拟器或手机(华为Ascend P1)上面运行时,没有显示任何标签.

我按照Android文档中的教程如何在Fragment中使用Tabhost,但我总是得到
The method setup(android.content.Context, android.support.v4.app.FragmentManager, int) in the type FragmentTabHost is not applicable for the arguments (android.content.Context, android.app.FragmentManager, int)
Run Code Online (Sandbox Code Playgroud)
我的设置命令是这样的:
mTabHost.setup( getActivity().getApplicationContext(), getChildFragmentManager(), R.layout.fragment_vc_view);
Run Code Online (Sandbox Code Playgroud) android-tabhost ×10
android ×9
tabs ×3
divider ×1
eclipse ×1
java ×1
listview ×1
mono ×1
tabactivity ×1
tabwidget ×1