2012-04-01 7 views
0

私は初心者アンドロイドの開発者です。私は自然に多くの質問をしています:) タブ付きのアクティビティを含むアプリケーションを設計したいと思います。 3つのImageButtonと、これらのボタンの間に小さな除数があります。ボタンの1つを押すと、そのボタンがフォーカスされます。私の質問は:どのように私はtabhost/tabwidgetのスタイルを変更できますか?ボタンが押されていれば1枚の写真があります。私はアンドロイドのデフォルトの強調表示を必要としません何とかそれを上書きすることはできますか?AndroidカスタムTabWidget

ありがとうございます!

Brで、ピーター

答えて

2

これはあなたを助けるでしょう:

<LinearLayout 
     android:id="@+id/header" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/headerContent" 
     android:orientation="horizontal" 
     android:background="@drawable/bg_seablue" 
     android:padding="10dip"> 

     <Button 
      android:layout_height="wrap_content" 
      android:id="@+id/tabOne" 
      android:layout_width="fill_parent" 
      android:layout_weight="1.0" 
      android:background="@drawable/bg_tabs" 
      android:padding="10dp" 
      android:text="Tab 1" 
      android:textColor="#000000" 
      android:textSize="16dip" 
      android:layout_marginRight="2dp" 
      android:onClick="onClick"/> 

     <Button 
      android:layout_height="wrap_content" 
      android:id="@+id/tabTwo" 
      android:layout_width="fill_parent" 
      android:layout_weight="1.0" 
      android:background="@drawable/bg_tabs" 
      android:padding="10dp" 
      android:text="Tab 2" 
      android:textColor="#000000" 
      android:textSize="16dip" 
      android:layout_marginRight="2dp" 
      android:onClick="onClick"/> 

     <Button 
      android:layout_height="wrap_content" 
      android:id="@+id/tabThree" 
      android:layout_width="fill_parent" 
      android:layout_weight="1.0" 
      android:textColor="#000000" 
      android:background="@drawable/bg_tabs" 
      android:padding="10dp" 
      android:text="Tab 3" 
      android:textSize="16dip" 
      android:layout_marginRight="2dp" 
      android:onClick="onClick"/> 

    </LinearLayout> 

次のコードは、タブのBGのためである:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_pressed="true" > 
     <shape> 
      <solid 
       android:color="#d2d2d2" /> 
      <stroke 
       android:width="1dp" 
       android:color="#000000" /> 
      <corners 
       android:radius="3dp" /> 
     </shape> 
    </item> 
    <item> 
     <shape> 
      <gradient 
       android:startColor="#ffffff" 
       android:endColor="#ffffff" 
       android:angle="270" /> 
      <stroke 
       android:width="1dp" 
       android:color="#000000" /> 
      <corners 
       android:radius="3dp" /> 
     </shape> 
    </item> 
</selector> 

に押されたときに他のページを表示するにはボタンは次のコードを使用します。

public void onClick(View v) { 

     Intent intent = new Intent(); 
     intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); 

     switch(v.getId()){ 

      case R.id.tabOne: 
       intent = new Intent(this, tabOne.class); 
      break; 

      case R.id.tabTwo: 
       intent = new Intent(this, tabTwo.class); 
      break; 

      case R.id.tabThree: 
       intent = new Intent(this, tabThree.class); 
      break; 

     } 

     startActivity(intent); 
     finish(); 
     overridePendingTransition(0, 0); 

    } 

これはあなたに十分に役立ちます、私はそれを確信しています。楽しいコーディングをしてください!

+0

こんにちはXonarial、あなたの答えに感謝します。私はこの方法を試しましたが、それは悪くはありませんが、私がここで欲しいのは、のTabActivityと同様のレイアウトです。ポイントは私が何とかの要素を修正する必要がありますが、私はどのように... – hcpeter

+0

こんにちは、これが助けて欲しい: http://joshclemm.com/blog/?p=136 – Xarialon