0

Как установить выравнивание текста и цвет делителя в виджетах татуировки.установить цвет вкладки, разделитель и выравнивание текста в android

mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); 
    mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); 


    Bundle b = new Bundle(); 
    b.putString("key", "Category"); 
    mTabHost.addTab(mTabHost.newTabSpec("Category").setIndicator("Category"), 
      CategoryFragment.class, b); 

    b = new Bundle(); 
    b.putString("key", "Activity"); 
    mTabHost.addTab(mTabHost.newTabSpec("Activity") 
      .setIndicator("Activity"), ActivityFragment.class, b); 

    b = new Bundle(); 
    b.putString("key", "Chart"); 
    mTabHost.addTab(mTabHost.newTabSpec("Chart").setIndicator("Chart"), 
      ChartFragment.class, b); 
    mTabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.tab_selector); 
    mTabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.tab_selector); 
    mTabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.tab_selector); 

    mTabHost.getTabWidget().setShowDividers(TabWidget.SHOW_DIVIDER_MIDDLE); 
    mTabHost.getTabWidget().setDividerDrawable(R.color.white); 

tab_selector XML -

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:drawable="@color/brown" android:state_selected="true"/> 
    <item android:drawable="@color/black" android:state_selected="false"/> 
    <item android:drawable="@color/red"/> 

</selector> 

расположение XML -

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <FrameLayout 
     android:id="@+id/realtabcontent" 
     android:layout_width="match_parent" 
     android:layout_height="0dip" 
     android:layout_weight="1" /> 

    <android.support.v4.app.FragmentTabHost 
     android:id="@android:id/tabhost" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:foreground="@color/final_red" 
     android:textAlignment="center" 
     android:layout_gravity="center_vertical" 

     android:foregroundGravity="center" > 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="50dp" 
      android:layout_height="0dp" 
      android:layout_weight="0" /> 
    </android.support.v4.app.FragmentTabHost> 

</LinearLayout> 

Я использовал setDividerDrawable, но я не могу видеть разделитель после выполнения кода. Также я хочу показать разделитель между вкладками. Как я могу сделать. На прилагаемом рисунке я хочу делитель между категориями, активностью и графикой. И текст должен быть выровнен по центру

enter image description here

+2

добавить 1 строку перед setdividerdrawble tabhost.getTabWidget() setShowDividers (TabWidget.SHOW_DIVIDER_MIDDLE);. –

+0

с вами?> –

+0

@DigveshPatel Проверить обновленное сообщение и logcat error –

ответ

0

Это как я сделал TabView использованием FragmentTabHost и TabWidget. Попробуйте это:

<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" > 

     <HorizontalScrollView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:scrollbars="none" > 

      <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#ff0000" 
       android:gravity="center" 
       android:orientation="horizontal" 
       android:scrollbars="none" 
       android:showDividers="middle" 
       android:soundEffectsEnabled="true" 
       android:splitMotionEvents="true" 
       android:tabStripEnabled="true" 
       android:textAlignment="inherit" 
       android:textDirection="inherit" /> 
     </HorizontalScrollView> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    </LinearLayout> 

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

EDIT

private FragmentTabHost mTabHost; 
DatabaseHandler db = new DatabaseHandler(this); 
SharedPreferences preferences; 
Editor editor; 

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

    setContentView(R.layout.activity_main); 

    preferences = getApplicationContext().getSharedPreferences("My Loging", 
      Context.MODE_PRIVATE); 

    editor = preferences.edit(); 

    mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); 

    mTabHost.setup(this, getSupportFragmentManager(), 
      android.R.id.tabcontent); 
    mTabHost.addTab(
      mTabHost.newTabSpec("Home").setIndicator("Home", 
        getResources().getDrawable(R.drawable.home_icon)), 
      HomeFragment.class, null); 
    mTabHost.addTab(
      mTabHost.newTabSpec("Product").setIndicator("Product", 
        getResources().getDrawable(R.drawable.home_icon)), 
      ProductFragment.class, null); 
    mTabHost.addTab(
      mTabHost.newTabSpec("MyOrder").setIndicator("MyOrder", 
        getResources().getDrawable(R.drawable.my_order_icon)), 
      MyOrderFragment.class, null); 

    mTabHost.addTab(
      mTabHost.newTabSpec("AboutUs").setIndicator("About Us", 
        getResources().getDrawable(R.drawable.history_icon)), 
      AboutUsFragment.class, null); 

    mTabHost.addTab(
      mTabHost.newTabSpec("ContactUs").setIndicator("Contact Us", 
        getResources().getDrawable(R.drawable.history_icon)), 
      ContactUsFragment.class, null); 

} 
+0

вы можете разместить код, связанный Java для tab –

+0

Отредактируйте Редактировать. – Shvet

+0

Для вкладок, принимающих цвет по умолчанию, Как добавить пользовательский фон, как показано на картинке? Также не работает Центр обработки текста –

Смежные вопросы