首先我非常新的Android和我不知道很多關於它。我正在嘗試玩它,我現在下面這個教程: http://www.androidhive.info/2011/08/android-tab-layout-tutorial/爲什麼不能在drawable下訪問xml文件?所有的
我創建了一個類,如下
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
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use grey -->
<item android:drawable="@drawable/photo-hover"
android:state_selected="true" />
<!-- When not selected, use white-->
<item android:drawable="@drawable/photo-unhover" />
</selector>
icon_songs_tab.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use grey -->
<item android:drawable="@drawable/music-hover"
android:state_selected="true" />
<!-- When not selected, use white-->
<item android:drawable="@drawable/music-unhover" />
</selector>
icon_videos_tab.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use grey -->
<item android:drawable="@drawable/video-hover"
android:state_selected="true" />
<!-- When not selected, use white-->
<item android:drawable="@drawable/video-unhover" />
</selector>
現在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_.]
這是問題謝謝你:) – user1720616