我创建了一个类,如下
package com.example.tabbedactivity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class TabbedActivity extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tabbed);
TabHost tabHost = getTabHost();
// Tab for Photos
TabSpec photospec = tabHost.newTabSpec("Photos");
// setting Title and Icon for the Tab
photospec.setIndicator("Photos", getResources().getDrawable(R.drawable.icon_photos_tab));
Intent photosIntent = new Intent(this, PhotosActivity.class);
photospec.setContent(photosIntent);
// Tab for Songs
TabSpec songspec = tabHost.newTabSpec("Songs");
songspec.setIndicator("Songs", getResources().getDrawable(R.drawable.icon_songs_tab));
Intent songsIntent = new Intent(this, SongsActivity.class);
songspec.setContent(songsIntent);
// Tab for Videos
TabSpec videospec = tabHost.newTabSpec("Videos");
videospec.setIndicator("Videos", getResources().getDrawable(R.drawable.icon_videos_tab));
Intent videosIntent = new Intent(this, VideosActivity.class);
videospec.setContent(videosIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(photospec); // Adding photos tab
tabHost.addTab(songspec); // Adding songs tab
tabHost.addTab(videospec); // Adding videos ta
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_tabbed, menu);
return true;
}
}
,并相应地我已根据可绘制三个XML文件等示于下 icon_photos_tab.xml
android:state_selected="true" />
icon_songs_tab.xml
android:state_selected="true" />
icon_videos_tab.xml
android:state_selected="true" />
现在IDE显示问题,当我尝试访问下绘制这些XML文件编码的精确行如下所示的是TabbedActivity.java(类的一部分,该我已以上示出)
TabSpec songspec = tabHost.newTabSpec("Songs");
songspec.setIndicator("Songs", getResources().getDrawable(R.drawable.icon_songs_tab));
TabSpec photospec = tabHost.newTabSpec("Photos");
// setting Title and Icon for the Tab
photospec.setIndicator("Photos", getResources().getDrawable(R.drawable.icon_photos_tab));
TabSpec videospec = tabHost.newTabSpec("Videos");
videospec.setIndicator("Videos", getResources().getDrawable(R.drawable.icon_videos_tab));
和误差说
个
在该行 多个标志 - icon_photos_tab不能得到解决或无法在现场 - R.drawable不能被解析为一个变量
究竟可能是什么问题(我真的很新的Android。 。这是一种liek我的第一个应用程序,我havenot通过任何理论)
更新 走后,我得到了控制台上以下误差修改
[2013-01-12 12:32:02 - TabbedActivity] res\drawable-ldpi\video-hover.png: Invalid file name: must contain only [a-z0-9_.]
[2013-01-12 12:32:02 - TabbedActivity] res\drawable-mdpi\video-hover.png: Invalid file name: must contain only [a-z0-9_.]
[2013-01-12 12:32:02 - TabbedActivity] res\drawable-xhdpi\video-hover.png: Invalid file name: must contain only [a-z0-9_.]
[2013-01-12 12:32:02 - TabbedActivity] res\drawable-hdpi\video-unhover.png: Invalid file name: must contain only [a-z0-9_.]
[2013-01-12 12:32:02 - TabbedActivity] res\drawable-ldpi\video-unhover.png: Invalid file name: must contain only [a-z0-9_.]
[2013-01-12 12:32:02 - TabbedActivity] res\drawable-mdpi\video-unhover.png: Invalid file name: must contain only [a-z0-9_.]
[2013-01-12 12:32:02 - TabbedActivity] res\drawable-xhdpi\video-unhover.png: Invalid file name: must contain only [a-z0-9_.]