2012-05-02 11 views
5

¿Cómo consigo mis botones de ficha para que parezca enter image description herebotones de ficha personalizados

¿Cuál sería la forma más sencilla de hacer esto si tengo un estirable en esa forma también ???

+1

Creación de diseños xml para selectores pero no encajan correctamente en las pestañas nativas –

+0

¿Tiene una pregunta específica? ¿Con qué parte de la implementación estás teniendo problemas? –

+0

básicamente, he intentado usar el método tabspec.setindicator con el dibujable, pero eso no encaja bien con el diseño, también probé un diseño xml personalizado en ese método, así que quería saber si había de otra forma podría cambiar la apariencia nativa de las pestañas –

Respuesta

3

simplemente se puede aplicar pestañas para su aplicación como esta

en método onCreate

TabHost tabHost = getTabHost(); 
tabHost.setCurrentTabByTag("First"); 

TabSpec firstTab = tabHost.newTabSpec("First"); 
firstTab.setIndicator("firstTab",getResources().getDrawable(R.drawable.ic_action_first)); //drawable 1 
firstTab.setContent(R.id.first_content); //View 
tabHost.addTab(firstTab); 

TabSpec secondTab = tabHost.newTabSpec("Second"); 
secondTab.setIndicator("secondTab",getResources().getDrawable(R.drawable.ic_action_second)); //drawable 2 
secondTab.setContent(R.id.second_content); //View 
tabHost.addTab(secondTab); 

TabSpec thirdTab = tabHost.newTabSpec("Third"); 
thirdTab.setIndicator("thirdTab",getResources().getDrawable(R.drawable.ic_action_third)); //drawable 3 
thirdTab.setContent(R.id.third_content); //View 
tabHost.addTab(thirdTab); 

tabHost.setCurrentTab(0); 

en el archivo xml

<TabHost android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost"> 
    <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> 
     <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /> 
     <FrameLayout android:id="@android:id/tabcontent" android:layout_width="wrap_content" android:layout_height="wrap_content" > 

      <LinearLayout android:id="@+id/first_content" android:layout_width="fill_parent" android:layout_height="fill_parent"> 
       <TextView android:text="first_tab" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
      </LinearLayout> 

      <LinearLayout android:id="@+id/second_content" android:layout_width="fill_parent" android:layout_height="fill_parent"> 
       <TextView android:text="second_tab" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
      </LinearLayout> 

      <LinearLayout android:id="@+id/third_content" android:layout_width="fill_parent" android:layout_height="fill_parent"> 
       <TextView android:text="third_tab" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
      </LinearLayout> 
     </FrameLayout> 

    </LinearLayout> 
    </TabHost> 

llame a su estirable en getResources() getDrawable (R.drawable.drawableid)).;

+1

, cambiar el tamaño de tus drawables.go a android assert studio y generar íconos de pestañas usando tus herramientas. Aquí está el enlace http: //android-ui-utils.googlecode. com/hg/asset-studio/dist/index.html pls no se olvide de calificar mi respuesta :) – Hassy31

1

Algo que se podría hacer en su actividad:

private TabHost mTabHost ; 
@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.my_layout); 

     mTabHost = (TabHost) findViewById(android.R.id.tabhost); 
     mTabHost.setup(); 
     // We create a webview for one tab for example 
     WebView wv = new WebView(this); 
     // add url and options on this webview 
     setupTab(wv, "My Title"); 
} 
private void setupTab(final View view, final String tag) { 
     View tabview = createTabView(mTabHost.getContext(), tag); 
     TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(new TabContentFactory() { 
      public View createTabContent(String tag) {return view;} 
     }); 

     mTabHost.addTab(setContent); 
    } 
// this is the method for customize tabs 
    private static View createTabView(final Context context, final String text) { 
     View view = LayoutInflater.from(context).inflate(R.layout.layout_tabwidget_custom, null); 
     TextView tv = (TextView) view.findViewById(R.id.tabsText); 
     tv.setText(text); 
     return view; 
    } 

En el R.layout.layout_tabwidget_custom:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tabsLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/selector_tab_bg" 
    android:gravity="center" 
    android:orientation="vertical" 
    android:padding="10dip" > 

    <TextView 
     android:id="@+id/tabsText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Title" 
     android:textColor="@drawable/selector_tab_text" 
     android:textSize="15dip" /> 

</LinearLayout> 
0

He hecho un trabajo similar al siguiente. Como Android no ayuda mucho, personalizando las pestañas, solo hago cuatro pestañas y las coloco al final de cada archivo xml. Todas sus actividades se verían similares de esta manera y daría una vista como pestañas.

+0

¿Podría darme un ejemplo para eso? –

+0

No creo que haya ninguna necesidad de ejemplo ya que es muy simple. Todo lo que tiene que hacer es agregar cuatro botones en la parte inferior del xml de cada actividad y llamar a la acción apropiada contra ellos. – MrWaqasAhmed

+1

¿Has probado mi solución a continuación? –

Cuestiones relacionadas