2012-01-23 12 views
0

私はTabLayoutの例を試しています。TabWidgetsにアイコンを表示しない

私はほとんどすべてをコピーして貼り付けています。私はちょうどタブにアイコンを取得しないでください。それらはstate-list xmlとともにdrawableフォルダにあります。

私は(私がうまくいけば)既定のアプリケーションアイコンを参照しようとしましたが、タブに表示されません。

コードで見られるようにタブのタイトルを「Uno、Dos、Tres」に変更しようとしましたが、タブタイトルは変更されますが、常に大文字で表示されます。

package com.example.androidtablayout; 

import android.app.TabActivity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.widget.TabHost; 
import android.widget.TabHost.TabSpec; 

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(); 

     // Tab for Photos 
     TabSpec photospec = tabHost.newTabSpec("Photos"); 
     // setting Title and Icon for the Tab 
     photospec.setIndicator("Uno", getResources().getDrawable(R.drawable.ic_tab_livestreaming)); 
     Intent photosIntent = new Intent(this, PhotosActivity.class); 
     photospec.setContent(photosIntent); 

     // Tab for Songs 
     TabSpec songspec = tabHost.newTabSpec("Songs"); 
     songspec.setIndicator("Dos", getResources().getDrawable(R.drawable.ic_tab_livestreaming)); 
     Intent songsIntent = new Intent(this, SongsActivity.class); 
     songspec.setContent(songsIntent); 

     // Tab for Videos 
     TabSpec videospec = tabHost.newTabSpec("Videos"); 
     videospec.setIndicator("Tres", getResources().getDrawable(R.drawable.ic_tab_livestreaming)); 
     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 tab 
    } 
} 

UPDATE:

それは私が誤ってそれを解決したようです。

私はちょうどこれを追加しました:

<activity 
      android:name=".AndroidTabLayoutActivity" 
      android:label="@string/app_name" 
      android:theme="@android:style/Theme.NoTitleBar"> 

私のManifest.xmlにデフォルトのアプリケーションのタイトルはレイアウトの上から消えるようにしよう。これはアイコンとタイトルを示すレイアウトの全体を小文字に変更したようです。

これがどのように動作するかはまだ分かりません。誰もこれにいくつかの光を投げることができますか?

ありがとうございました。

答えて

0

main.xml

<?xml version="1.0" encoding="utf-8"?> 

    <TabHost android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/tabHost" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    > 
    <TabWidget 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@android:id/tabs" 
    /> 
    <FrameLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@android:id/tabcontent" 
    > 
    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/tab1" 
    android:orientation="vertical" 
    android:paddingTop="60px" 
    > 
    <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="100px" 
    android:text="This is tab1" 
    android:id="@+id/txt1" 
    />  

    </LinearLayout> 

    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/tab2" 
    android:orientation="vertical" 
    android:paddingTop="60px" 
    > 
    <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="100px" 
    android:text="This is tab 2" 
    android:id="@+id/txt2" 
    /> 

    </LinearLayout> 

     <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/tab3" 
    android:orientation="vertical" 
    android:paddingTop="60px" 
    > 
    <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="100px" 
    android:text="This is tab 3" 
    android:id="@+id/txt3" 
    /> 

    </LinearLayout> 
    </FrameLayout> 

    </TabHost> 

MainActivity.java

public class MainActivity extends TabActivity{ 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.main); 
TabHost tabHost=(TabHost)findViewById(R.id.tabHost); 
tabHost.setup(); 

TabSpec spec1=tabHost.newTabSpec("Tab 1"); 
spec1.setContent(R.id.tab1); 
spec1.setIndicator("Tab 1",getResources().getDrawable(R.drawable.flash)); 

TabSpec spec2=tabHost.newTabSpec("Tab 2"); 
spec2.setIndicator("Tab 2",getResources().getDrawable(R.drawable.sun)); 
spec2.setContent(R.id.tab2); 

TabSpec spec3=tabHost.newTabSpec("Tab 3"); 
spec3.setIndicator("Tab 3",getResources().getDrawable(R.drawable.chart)); 
spec3.setContent(R.id.tab3); 

tabHost.addTab(spec1); 
tabHost.addTab(spec2); 
tabHost.addTab(spec3); 
} 
} 
、このコードを試してみてください
関連する問題