Android中的“自定义”标签-使用“ setIndicator”时出现错误

Android中的“自定义”标签-使用“ setIndicator”时出现错误,第1张

概述我正在尝试在我的android应用中创建自定义标签,我得到了一些示例代码,但是该代码在setIndicator方法中显示错误…这是我的代码我遇到的错误是-类型TabHost.TabSpec中的setIndicator(CharSequence)方法不适用于自变量(TextView)packagecom.myapp;importandroid.app.Activity;

我正在尝试在我的android应用中创建自定义标签,我得到了一些示例代码,但是该代码在setIndicator方法中显示错误…这是我的代码

我遇到的错误是-类型TabHost.TabSpec中的setIndicator(CharSequence)方法不适用于自变量(TextVIEw)

package com.myapp;import androID.app.Activity;import androID.graphics.color;import androID.os.Bundle;import androID.vIEw.Gravity;import androID.vIEw.VIEw;import androID.Widget.FrameLayout;import androID.Widget.linearLayout;import androID.Widget.TabHost;import androID.Widget.TabWidget;import androID.Widget.TextVIEw;import androID.Widget.linearLayout.LayoutParams;import androID.Widget.TabHost.TabContentFactory;import androID.Widget.TabHost.TabSpec;//Custom Tabspublic class MyActivity extends Activity {int tabHeight = 40;@OverrIDepublic voID onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);linearLayout main = new linearLayout(this);main.setorIEntation(linearLayout.VERTICAL);setContentVIEw(main);TabHost tabs = new TabHost(this);tabs.setID(androID.R.ID.tabhost);main.addVIEw(tabs);TabWidget tabWidget = new TabWidget(this);tabWidget.setID(androID.R.ID.tabs);tabs.addVIEw(tabWidget);FrameLayout tabContent = new FrameLayout(this);tabContent.setID(androID.R.ID.tabcontent);tabContent.setpadding(0, tabHeight, 0, 0);tabs.addVIEw(tabContent);TextVIEw content = new TextVIEw(this);content.setText("This is the Frame Content");content.setID(100);tabs.setup();TabSpec tspec1 = tabs.newTabSpec("Tab1");tspec1.setIndicator(makeTabIndicator("One"));tspec1.setContent(new PreExistingVIEwFactory(content));tabs.addTab(tspec1);TabSpec tspec2 = tabs.newTabSpec("Tab2");tspec2.setIndicator(makeTabIndicator("Two"));tspec2.setContent(new PreExistingVIEwFactory(content));tabs.addTab(tspec2);TabSpec tspec3 = tabs.newTabSpec("Tab3");tspec3.setIndicator(makeTabIndicator("Three"));tspec3.setContent(new PreExistingVIEwFactory(content));tabs.addTab(tspec3);}private TextVIEw makeTabIndicator(String text){TextVIEw tabVIEw = new TextVIEw(this);LayoutParams lp3 = new LayoutParams(LayoutParams.WRAP_CONTENT, tabHeight, 1);lp3.setmargins(1, 0, 1, 0);tabVIEw.setLayoutParams(lp3);tabVIEw.setText(text);tabVIEw.setTextcolor(color.WHITE);tabVIEw.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL);tabVIEw.setBackgroundDrawable( getResources().getDrawable(R.drawable.tab_indicator));tabVIEw.setpadding(13, 0, 13, 0);return tabVIEw;}class PreExistingVIEwFactory implements TabContentFactory{private final VIEw preExisting;protected PreExistingVIEwFactory(VIEw vIEw){preExisting = vIEw;}public VIEw createTabContent(String tag) {return preExisting;}}}

任何人都可以帮助我解决此问题…

提前谢谢..
克里斯

解决方法:

不幸的是,方法setIndicator(VIEw vIEw)仅适用于AndroID 1.6及更高版本(版本4).如果您支持AndroID 1.5(版本3),则只能使用setIndicator(CharSequence标签)将String / CharSequence用作指标.

参考编号:http://developer.android.com/reference/android/widget/TabHost.TabSpec.html#setIndicator

请注意,方法setIndicator(VIEw vIEw)为“ Since:API Level 4”

总结

以上是内存溢出为你收集整理的Android中的“自定义”标签-使用“ setIndicator”时出现错误全部内容,希望文章能够帮你解决Android中的“自定义”标签-使用“ setIndicator”时出现错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1068433.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存