Android的标签图标不显示 [英] android Tab icons dont show up

查看:115
本文介绍了Android的标签图标不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林新的Andr​​oid。

现在我试着去找到工作选项卡的布局。香港专业教育学院所做的一切,就像在Android的TabView的教程中,应用程序运行正常,但问题是,我不看到,香港专业教育学院确定他们ic_tab_artists.xml任何图标。只有文字。

我猜它是与主题,是默认的一个或风格或什么都。香港专业教育学院试图改变它,但它并没有在所有帮助,仍然只是一个文本。

即时通讯使用的Andr​​oid SDK V4.03。

我敢肯定有足够的Andr​​oid大师,将帮助,所以在此先感谢。

这是我的.xml使用图标定义:

  XML版本=1.0编码=UTF-8&GT?;
<选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>


    <! - 当选择,使用灰色 - >
<项目机器人:可绘制=@可绘制/ ic_tab_artists_grey
      机器人:state_selected =真/>


    <! - 如果没有选择(默认值),用白 - >
<项目机器人:可绘制=@可绘制/ ic_tab_artists_white/>

< /选择器>
 

和我的主要HolePage活动:

  @燮pressWarnings(德precation)
公共类HolePage扩展TabActivity {


@覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.hole_page);

    // TABS

    资源RES = getResources(); //资源对象获取可绘
    TabHost tabHost = getTabHost(); //活动TabHost
    TabHost.TabSpec规范; //可重复使用的则tabspec为每个标签
    意向意图; //可重复使用意向为每个标签

    //创建一个Intent来启动一个活动的标签(重复使用)
    意图=新的意图()setClass(这一点,HolePageScores.class)。

    //初始化则tabspec为每个标签,并把它添加到TabHost
    规格= tabHost.newTabSpec(分)。setIndicator(分数,
                      res.getDrawable(R.drawable.tab_scores_icons))
                  .setContent(意向);

    tabHost.addTab(规范);

    //执行相同的其他标签 - 信息
    意图=新的意图()setClass(这一点,HolePageInfo.class)。
    规格= tabHost.newTabSpec(信息)。setIndicator(信息,
                      res.getDrawable(R.drawable.tab_scores_icons))
                  .setContent(意向);
    tabHost.addTab(规范);

    //执行相同的其他标签 - 热门
    意图=新的意图()setClass(这一点,HolePageTop.class)。
    规格= tabHost.newTabSpec(顶)。setIndicator(顶,
                      res.getDrawable(R.drawable.tab_scores_icons))
                  .setContent(意向);
    tabHost.addTab(规范);

    //执行相同的其他标签 - 孔
    意图=新的意图()setClass(这一点,HolePageHole.class)。
    规格= tabHost.newTabSpec(洞)。setIndicator(一杆进洞,
                      res.getDrawable(R.drawable.tab_scores_icons))
                  .setContent(意向);
    tabHost.addTab(规范);

    //执行相同的其他选项卡 - 帕
    意图=新的意图()setClass(这一点,HolePagePar.class)。
    规格= tabHost.newTabSpec(相提并论)。setIndicator(帕,
                      res.getDrawable(R.drawable.tab_scores_icons))
                  .setContent(意向);
    tabHost.addTab(规范);

    //设置默认TAB2
    tabHost.setCurrentTab(1);

}

}
 

解决方案

不知道多深约的主题,我发现指定的主题 @android:款式/ Theme.NoTitleBar 在应用程序清单解决问题和图标显示在标签。

 <应用
    机器人:图标=@可绘制/ ic_launcher
    机器人:标签=@字符串/ APP_NAME
    机器人:主题=@安卓风格/ Theme.NoTitleBar
    >
    &所述;! - 清单 - >
< /用途>
 

希望,可以帮助!

Im new with the Android.

Right now Im trying to get work Tab layout. Ive done everything just like in Android TabView tutorial, app runs ok, but the problem is that I dont see any icons that Ive defined them in ic_tab_artists.xml. There is text only.

I guess it has something to do with theme that is default one or style or what ever. Ive tried to change it but it didnt help at all, still just a text.

Im using Android SDK v4.03.

Im sure there are enough Android gurus that will help, so thanks in advance.

This is my .xml defining using icons:

?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">


    <!-- When selected, use grey -->
<item android:drawable="@drawable/ic_tab_artists_grey" 
      android:state_selected="true" /> 


    <!-- When not selected (default), use white-->  
<item android:drawable="@drawable/ic_tab_artists_white" />

</selector>

And my main HolePage Activity:

@SuppressWarnings("deprecation")
public class HolePage extends TabActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.hole_page);

    //TABS      

    Resources res = getResources(); // Resource object to get Drawables
    TabHost tabHost = getTabHost();  // The activity TabHost
    TabHost.TabSpec spec;  // Reusable TabSpec for each tab
    Intent intent;  // Reusable Intent for each tab

    // Create an Intent to launch an Activity for the tab (to be reused)
    intent = new Intent().setClass(this, HolePageScores.class);

    // Initialize a TabSpec for each tab and add it to the TabHost
    spec = tabHost.newTabSpec("scores").setIndicator("Scores",
                      res.getDrawable(R.drawable.tab_scores_icons))
                  .setContent(intent);

    tabHost.addTab(spec);

    // Do the same for the other tabs - Info
    intent = new Intent().setClass(this, HolePageInfo.class);
    spec = tabHost.newTabSpec("info").setIndicator("Info",
                      res.getDrawable(R.drawable.tab_scores_icons))
                  .setContent(intent);
    tabHost.addTab(spec);

    // Do the same for the other tabs - Top
    intent = new Intent().setClass(this, HolePageTop.class);
    spec = tabHost.newTabSpec("top").setIndicator("Top",
                      res.getDrawable(R.drawable.tab_scores_icons))
                  .setContent(intent);
    tabHost.addTab(spec);

    // Do the same for the other tabs - Hole
    intent = new Intent().setClass(this, HolePageHole.class);
    spec = tabHost.newTabSpec("hole").setIndicator("Hole",
                      res.getDrawable(R.drawable.tab_scores_icons))
                  .setContent(intent);
    tabHost.addTab(spec);

    // Do the same for the other tabs - Par
    intent = new Intent().setClass(this, HolePagePar.class);
    spec = tabHost.newTabSpec("par").setIndicator("Par",
                      res.getDrawable(R.drawable.tab_scores_icons))
                  .setContent(intent);
    tabHost.addTab(spec);

    //Set default tab2
    tabHost.setCurrentTab(1);

}

}

解决方案

without knowing much in depth about themes, i have discovered that specifying the theme @android:style/Theme.NoTitleBar in the application manifest solves the issue and the icons show up in the tabs.

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar" 
    >
    <!-- MANIFEST -->
</application>

Hope, that helps!

这篇关于Android的标签图标不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆