我得到了一些适用TabLayout
于 Android 的示例代码,并对其进行了修改以满足我的需要。
问题是,当我尝试重写它时,我遇到了一些弃用错误,当我打开示例时,没有出现错误。
起初我以为是这样,minSdkversion
所以我在示例中更改了它,但仍然没有发生任何事情。
我无法让图标在选项卡中正确显示,因此它可能与此弃用有关。
谁能启发我?这是我的代码:
package com.example.myapp;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost.TabSpec;
//notice that here eclipse won't let me import android.widget.TabHost
//but i use it when i create the tabhost variable
public class TabHost extends TabActivity {
//the 'TabActivity' part above gets crossed-over although that doesn't happen
//in the sample
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tab_host);
android.widget.TabHost tabHost = getTabHost();
TabSpec absSpec = tabHost.newTabSpec("Absences");
absSpec.setIndicator("Absences", getResources().getDrawable(R.drawable.abs));
Intent int1 = new Intent(this, Absences.class);
absSpec.setContent(int1);
tabHost.addTab(absSpec);
}
}
这是示例:
package com.example.androidtablayout;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost.TabSpec;
import android.widget.TabHost;
public class AndroidTabLayoutActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabSpec photospec = tabHost.newTabSpec("Photos");
photospec.setIndicator("Photos", getResources().getDrawable(R.drawable.icon_photos_tab));
Intent photosIntent = new Intent(this, PhotosActivity.class);
photospec.setContent(photosIntent);
tabHost.addTab(photospec);
}
}