我正在尝试为应用程序实现以下背景…
对于背景图像(应用程序背景)…我在setContentVIEw(布局)中设置图像…通过添加此行,我得到运行时异常…
如果我在子活动中设置这个背景..我不会得到背景来填充完整的应用程序背景..任何想法什么是替代?
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的方法.
然后膨胀这样的视图:
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" en@R_403_5563@="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问题全部内容,希望文章能够帮你解决Android UI TabActivity问题所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)