为什么我TabHost的setIndicator设置了图片,但是我的应用显示却显示不出来呢 我发现只要我删除Manifest下面的这个设置就可以正常显示了这是为什么呢、? <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 个人感觉如下:现在的代码貌似不支持同时显示图片和文字一样,你去看系统的源代码,在TabHost.java中。final boolean exclusive = iconView.getVisibility() == View.GONE; final boolean bindIcon = !exclusive || TextUtils.isEmpty(mLabel); if (bindIcon && mIcon != null) { iconView.setImageDrawable(mIcon); iconView.setVisibility(VISIBLE); }这里有一个exclusive判断ImageView是否显示。再看对应的tab_indicator_holo.xml文件。<ImageView android:id="@android:id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:visibility="gone" />看到没有,这里是不显示图片的,也就是说,只有在文字为空的时候才显示图片。 个人理解是android自己定义的布局吧。如果你把AndroidManifest.xml中的代码去掉: <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />是可以显示的,应该是以前的代码支持双显示吧。------以上为个人想法。 楼主可以在AndroidManifest的Application中改变一下程序的主题:<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@android:style/Theme.Black" >这里改成了Tehme.Black 下面这样试试:TabHost mTabHost = getTabHost(); LayoutInflater inflater_tab1 = LayoutInflater.from(this); inflater_tab1.inflate(R.layout.mgtlayout, mTabHost.getTabContentView()); inflater_tab1.inflate(R.layout.testlayout, mTabHost.getTabContentView()); inflater_tab1.inflate(R.layout.conflayout, mTabHost.getTabContentView()); inflater_tab1.inflate(R.layout.runlayout, mTabHost.getTabContentView()); //mTabHost.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_bg_top));mTabHost.addTab(mTabHost .newTabSpec("tab_mgt") .setIndicator("系统管理",getResources().getDrawable(R.drawable.ic_home)) .setContent(R.id.LinearLayoutmgt) ); mTabHost.addTab(mTabHost .newTabSpec("tab_test") .setIndicator("测试模式",getResources().getDrawable(R.drawable.ic_test)) .setContent(R.id.LinearLayouttest) );mTabHost.addTab(mTabHost .newTabSpec("tab_conf") .setIndicator("设置模式",getResources().getDrawable(R.drawable.ic_set)) .setContent(R.id.LinearLayoutconf) ); mTabHost.addTab(mTabHost .newTabSpec("tab_run") .setIndicator("运行模式",getResources().getDrawable(R.drawable.ic_run)) .setContent(R.id.LinearLayoutrun) ); setIndicator的时候直接加上一个view就可以了 这个view可是是任何你自定义的就行了 jquerymobile+phonegap在安卓上表现很慢 android导入工程出错 怎样实现微信聊天一样的布局 XML的注释语法是啥? Android SDK安装问题 编译时说缺zlib.so,这个文件在哪个安装包里面啊 各位大神,为什么摄像头拍出的照片是横着的? android设备如何利用wifi direct实现无线中继 NDK-STACK的用法 做一个在线视频播放器,获取到了磁力链了,如何进行在线播放? 为何inflate其他的View过来却无法占满父布局? 求大神指教!急!
现在的代码貌似不支持同时显示图片和文字一样,你去看系统的源代码,在TabHost.java中。
final boolean exclusive = iconView.getVisibility() == View.GONE;
final boolean bindIcon = !exclusive || TextUtils.isEmpty(mLabel);
if (bindIcon && mIcon != null) {
iconView.setImageDrawable(mIcon);
iconView.setVisibility(VISIBLE);
}这里有一个exclusive判断ImageView是否显示。再看对应的tab_indicator_holo.xml文件。
<ImageView
android:id="@android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:visibility="gone" />
看到没有,这里是不显示图片的,也就是说,只有在文字为空的时候才显示图片。
个人理解是android自己定义的布局吧。
如果你把AndroidManifest.xml中的代码去掉:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
是可以显示的,应该是以前的代码支持双显示吧。------以上为个人想法。
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black" >这里改成了Tehme.Black
TabHost mTabHost = getTabHost(); LayoutInflater inflater_tab1 = LayoutInflater.from(this);
inflater_tab1.inflate(R.layout.mgtlayout, mTabHost.getTabContentView());
inflater_tab1.inflate(R.layout.testlayout, mTabHost.getTabContentView());
inflater_tab1.inflate(R.layout.conflayout, mTabHost.getTabContentView());
inflater_tab1.inflate(R.layout.runlayout, mTabHost.getTabContentView());
//mTabHost.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_bg_top));
mTabHost.addTab(mTabHost
.newTabSpec("tab_mgt")
.setIndicator("系统管理",getResources().getDrawable(R.drawable.ic_home))
.setContent(R.id.LinearLayoutmgt)
);
mTabHost.addTab(mTabHost
.newTabSpec("tab_test")
.setIndicator("测试模式",getResources().getDrawable(R.drawable.ic_test))
.setContent(R.id.LinearLayouttest)
);
mTabHost.addTab(mTabHost
.newTabSpec("tab_conf")
.setIndicator("设置模式",getResources().getDrawable(R.drawable.ic_set))
.setContent(R.id.LinearLayoutconf)
);
mTabHost.addTab(mTabHost
.newTabSpec("tab_run")
.setIndicator("运行模式",getResources().getDrawable(R.drawable.ic_run))
.setContent(R.id.LinearLayoutrun)
);