tabhost 위젯에서 텍스트 정렬 및 구분선 색상을 설정하는 방법.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 사용했다하지만 난 코드를 실행 한 후 구분선을 볼 수 없습니다. 또한 탭 사이에 구분선을 표시하려고합니다. 어떻게해야합니까? 첨부 된 그림에서 범주, 활동 및 차트 사이에 구분선이 필요합니다. 그리고 텍스트이 내가 FragmentTabHost
및 TabWidget
를 사용하여 TabView
을 만들어 어떻게
이 setdividerdrawble tabhost.getTabWidget() setShowDividers (TabWidget.SHOW_DIVIDER_MIDDLE) 전에 한 줄을 추가;. –
체크 아웃 하시겠습니까?> –
@DigveshPatel 업데이트 된 게시물 및 로그 켓 오류를 확인하십시오. –