<LinearLayout
android:id="@+id/tab_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/search_et_container_bottom_margin"
android:background="@drawable/search_result_header_background"
android:clickable="false"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="5" >
<TextView
android:id="@+id/institute_tab_label"
android:layout_width="0dp"
android:layout_height="@dimen/height48"
android:layout_weight="2.5"
android:background="@color/learnito_red"
android:clickable="true"
android:gravity="center"
android:text="@string/institutes"
android:textColor="@color/white"
android:textSize="@dimen/size18" />
<TextView
android:id="@+id/course_tab_label"
android:layout_width="0dp"
android:layout_height="@dimen/height48"
android:layout_weight="2.5"
android:clickable="true"
android:gravity="center"
android:text="@string/courses"
android:textColor="@color/black"
android:textSize="@dimen/size18" />
</LinearLayout>
</LinearLayout>
单击TextView时,我正在查看背景颜色以模拟选项卡式布局。
mTab1.setBackgroundColor(getResources().getColor(R.color.red));
mTab1.setTextColor(getResources().getColor(R.color.white));
mTab2.setBackgroundColor(getResources().getColor(R.color.white));
mTab2.setTextColor(getResources().getColor(R.color.black));
但是当尝试设置背景颜色时,线性布局的可绘制背景会消失。