【问题标题】:Android Tab icon for 4.0 and later适用于 4.0 及更高版本的 Android 选项卡图标
【发布时间】:2013-07-15 08:33:26
【问题描述】:

我想在标签上设置图标。我的代码是正确的,我确定。这是因为 android 版本的问题吗?我看了很多代码,但都是一样的。代码是;

package com.mesutemre.androidtabkullanimi;

import android.os.Bundle;
import android.app.Activity;
import android.app.ActivityGroup;
import android.app.TabActivity;
import android.content.Intent;
import android.view.Menu;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class MainActivity extends TabActivity {

@SuppressWarnings("deprecation")
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TabHost tabhost = getTabHost();
    tabhost.setup();
    tabhost.addTab(tabhost
            .newTabSpec("tabindis1")
            .setIndicator("SEKME1",
                    getResources().getDrawable(R.drawable.document))
            .setContent(new Intent(MainActivity.this, Sekme1Activity.class)));

    tabhost.addTab(tabhost
            .newTabSpec("tabindis2")
            .setIndicator("SEKME2",
                    getResources().getDrawable(R.drawable.music))
            .setContent(new Intent(MainActivity.this, Sekme1Activity.class)));

    tabhost.addTab(tabhost
            .newTabSpec("tabindis3")
            .setIndicator("SEKME3",
                    getResources().getDrawable(R.drawable.delete))
            .setContent(new Intent(MainActivity.this, Sekme1Activity.class)));

    tabhost.addTab(tabhost
            .newTabSpec("tabindis4")
            .setIndicator("SEKME4",
                    getResources().getDrawable(R.drawable.close))
            .setContent(new Intent(MainActivity.this, Sekme1Activity.class)));



}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

  }

我从一些链接中得知这是 4.0 及更高版本的问题。如何在选项卡上设置图标。

【问题讨论】:

  • 首先,您使用的是不推荐使用的方法。当您这样做时,它们将被弃用,因为您应该在新版本中以不同的方式做事(使用片段而不是活动)。

标签: android android-tabhost android-style-tabhost


【解决方案1】:

请尝试 setView 来设置 TextView 而不是 setIndicator。 将图标和指示器文本设置为 TextView。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-10
    • 1970-01-01
    • 2018-01-09
    • 1970-01-01
    • 2017-07-17
    相关资源
    最近更新 更多