2015-09-02 4 views
0

Я пытаюсь изменить текст вкладок TabHost на текст, сделав его на singleLine=true. Для этого я пытаюсь создать TextView и добавить этот атрибут singleLine. Проблема в том, что я не могу вставить этот TextView в TabHost.Как изменить название TabHost?

Как я мог это сделать?

Я пробую это.

XML TabHost

<android.support.v4.app.FragmentTabHost 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:layout_weight="0" 
      android:layout_gravity="bottom"> 
     </TabWidget> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" /> 
    </LinearLayout> 

</android.support.v4.app.FragmentTabHost> 

TextView

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:singleLine="true" 
     android:id="@+id/perfil" 
     android:text="teste de aba para tab host" 
     /> 

</LinearLayout> 

активность

public class AreaAlunoMainActivity extends FragmentActivity { 
    private FragmentTabHost mTabHost; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     setContentView(R.layout.areadoaluno_main); 
     mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); 
     mTabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent); 

     mTabHost.addTab(
       mTabHost.newTabSpec("perfil").setIndicator("Perfil", null).setContent(R.id.perfil), 
       PerfilFrag.class, null); 

    } 
} 
+0

вам нужно установить вкладку с настраиваемым макетом ..... – koutuk

+0

@koutuk как я мог это сделать? – FernandoPaiva

ответ

1
TabHost.TabSpec spec = mTabHost.newTabSpec(TAB_A); 
    spec.setContent(new TabHost.TabContentFactory() { 
     public View createTabContent(String tag) { 
      return findViewById(android.R.id.tabcontent); 
     } 
    }); 
    spec.setIndicator(createTabView(TAB_A, R.drawable.salonsphp)); 
    mTabHost.addTab(spec); 


    private View createTabView(final String text, final int id) { 
     View view =LayoutInflater.from(this).inflate(R.layout.yourcustomlayout,null); 
     ImageView imageView = (ImageView) view.findViewById(R.id.tab_icon); 
     imageView.setImageDrawable(getResources().getDrawable(id)); 
     ((TextView) view.findViewById(R.id.tab_text)).setText(text); 
     return view; 
    } 

you can set specifi. of tab like this..... 
Смежные вопросы