- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试为应用程序实现以下背景...
对于背景图像(应用程序背景)...我在 setContentView(布局)中设置图像...通过添加此行,我收到运行时异常...
如果我在子 Activity 中设置这个背景..我不会得到背景来填充整个应用程序背景..知道有什么选择吗?
public class HMITabActivity extends TabActivity{
private TabHost tabHost = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.background);
tabHost = getTabHost();
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
setTabHostColors();
}
});
tabHost.addTab(tabHost.newTabSpec("Tasks")
.setIndicator("Tasks", getResources().getDrawable(R.drawable.icon_task))
.setContent(new Intent(this, Tasks.class)));
tabHost.addTab(tabHost.newTabSpec("HMI")
.setIndicator("HMI", getResources().getDrawable(R.drawable.icon_hmi))
.setContent(new Intent(this, HMI.class)));
tabHost.addTab(tabHost.newTabSpec("Diagnostics")
.setIndicator("Diagnostics", getResources().getDrawable(R.drawable.icon_diagnostics))
.setContent(new Intent(this, Diagnostics.class)));
tabHost.addTab(tabHost.newTabSpec("About")
.setIndicator("About", getResources().getDrawable(R.drawable.icon_info))
.setContent(new Intent(this, Tasks.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
Intent intent = new Intent(BackgroundService.class.getName());
startService(intent);
}
private void setTabHostColors() {
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++) {
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.rgb(1, 1, 1)); //unselected
}
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.rgb(50, 120, 160)); // selected
}
}
最佳答案
为此你必须使用自定义选项卡,这里是代码试试这个:
tabHost= getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab1").setContent(new Intent(this, Activity2.class)).setIndicator(prepareTabView("Names",R.drawable.icon)));
其中 prepareTabView 是 Inflate View 的方法。然后像这样膨胀 View :
private View prepareTabView(String text, int resId) {
View view = LayoutInflater.from(this).inflate(R.layout.tabs, null);
ImageView iv = (ImageView) view.findViewById(R.id.TabImageView);
TextView tv = (TextView) view.findViewById(R.id.TabTextView);
iv.setImageResource(resId);
tv.setText(text);
return view;
}
标签 XML 看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:id="@+id/TabLayout"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:padding="5dip">
<ImageView android:id="@+id/TabImageView" android:src="@drawable/icon"
android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<TextView android:id="@+id/TabTextView" android:text="Text"
android:paddingTop="5dip" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="@color/black"
android:textAppearance="@style/TabTextViewStyle" />
</LinearLayout>
然后现在添加你喜欢的背景颜色..
关于Android UI TabActivity 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5567532/
public class HMITabActivity extends TabActivity{ @Override protected void onCreate(Bundle saved
我正在测试 TabActivity,每个选项卡中都有一个列表。 在运行应用程序时,选项卡的内容会像这样重叠。 在我单击选项卡后,重叠被清除。这是我的代码: testtabs.xml 布局:
我正在开发一个使用 TabActivity 的 android 示例项目。但由于现在已弃用,我将其替换为“fragment ” Activity 。现在我不知道用什么来代替, TabHost tabH
我有一个 TabActivity,想要捕捉和处理 HOME 和 BACK 的按下。我需要在哪里捕捉这些事件? 在我的 TabActivity 子类中,我实现了以下内容: @Override publi
我正在尝试向我的 TabActivty 添加动画。例如,当用户选择第二个选项卡时,我希望新 Activity 来自右侧。当用户选择第一个选项卡时,我希望 Activity 来自左侧。 我找到了如何添加
我该如何解释我的问题? 我有一个使用选项卡的应用程序(通过 Intent ,而不是 View )。我已经在每个 View 内实现了导航,没有任何问题,但我需要在全屏和横向模式(因此没有标签)的 Act
我有一个托管其他三个 Activity 的 TabActivity。 如果选择了第一个选项卡,我可以更改设备方向,一切正常。 如果我转到第二个或第三个选项卡并更改方向,选项卡子 Activity 的(
我想知道使用 Fragments(ActivityGroup 的新版本)有什么好处至于现在我可以用 TabActivity 做同样的事情。如果我想替换固定的 tabwidget 我可以将可见性设置为
我有一个包含三个选项卡的 TabActivity。拳头标签是问题所在。第一个选项卡加载 ActivityGroup。 OnCreate 它加载默认内容 View 。稍后在某个事件上,我们添加了不同的内
我的主要 Activity 是 TabActivity。 我有一些由选项卡 Activity 呈现的 Activity ,我想将其锁定为纵向。 在 AndroidManifest.xml 中,当我为
TabActivity 中的问题我的应用程序中有三个选项卡,每个选项卡都是不同的 Activity 。在第一个选项卡中,我有一个文本字段和 ListView ,用户可以通过它们进行搜索但是在搜索之后当
我在 TabActivity 中创建了三个选项卡onCreate . 如何在运行时隐藏一个选项卡? 最佳答案 要隐藏选项卡,您必须将其从 TabWidget 中删除。仅仅设置 INVISIBLE 是不
这个主题可能看起来与其他主题相似,但我还没有找到任何适用于这种情况的答案。 这就是我想要的:我有一个带菜单的 TabActivity,其中包含没有任何菜单的选项卡。当我按下菜单按钮时,我希望显示唯一的
我是 Android 开发的新手,当我制作我的第一个应用程序时感到非常兴奋(并且我认为完全理解它),但我就是无法运行它。它对我来说看起来很干净,我不确定根据调试信息要查找什么。至少解释一下我应该寻找什
我正在开发一个使用 tabs 和 fragments 的应用程序。 Google 正在提供 android 支持 v4.jar,以便我们也可以使用 api 1.6 的 fragment 。 我已经查看
我搜索了我的具体问题,但找不到问题的答案。 在我的应用程序中,我的主要 Activity 有一个包含 3 个选项卡的选项卡主机。所有三个选项卡都有一个包含项目的 ListView 。 选项卡 1 Li
我在这里看到了一些类似的帖子,但我还没有找到任何答案。我想在我的选项卡 Activity 中添加滑动手势,以便我能够使用该手势更改选项卡。 这是我的代码: public class Domicilia
我的 TabActivity 有一个类 public class DashboardActivity extends TabActivity 这有几个选项卡和一个操作栏。这些选项卡之一是项目列表。 p
我正在尝试为应用程序实现以下背景... 对于背景图像(应用程序背景)...我在 setContentView(布局)中设置图像...通过添加此行,我收到运行时异常... 如果我在子 Activity
好吧,我正在使用 TabActivity 为 api 8 开发和应用程序但我今天发现“此类已弃用。” 所以我们应该使用FragmentActivity从现在开始实现标签?但是当我想显示带有 Activ
我是一名优秀的程序员,十分优秀!