80,337
社区成员
发帖
与我相关
我的任务
分享
<LinearLayout
android:id="@+id/call_log_sub_tab_hw"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/call_log_sub_tab_padding_top"
android:paddingBottom="@dimen/call_log_sub_tab_padding_bottom"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:orientation="horizontal">
<!-- add sub tab at CallLogFragmentHw -->
</LinearLayout>
subTabLayout = (LinearLayout) view.findViewById(R.id.call_log_sub_tab_hw);
//init sub tab, add text view
for (int i = 0; i < mTabTitles.length; i++) {
TextView textView = new TextView(getActivity());
LogUtil.d("CallLogFragmentHw.setupView()", "tab i=" + i + "; rtl tab i=" + getRtlPosition(i));
if (getRtlPosition(i) == 0) {
textView.setBackgroundResource(R.drawable.call_log_sub_tab_bg_left_selector);
} else if (getRtlPosition(i) == mTabTitles.length - 1) {
textView.setBackgroundResource(R.drawable.call_log_sub_tab_bg_right_selector);
} else {
textView.setBackgroundResource(R.drawable.call_log_sub_tab_bg_middle_selector);
}
textView.setText(mTabTitles);
textView.setGravity(Gravity.CENTER);
textView.setTextAppearance(R.style.CallLogSubTabTextStyle);
subTabLayout.addView(textView);
textView.setOnClickListener(this);
if (startingTab == i) {
subTabSelected(textView, true);
}
}
<style name="CallLogSubTabTextStyle">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">1</item>
<item name="android:textSize">@dimen/sub_tab_hw_text_size</item>
<item name="android:textColor">@android:color/black</item>
<item name="android:clickable">true</item>
<item name="android:focusable">true</item>
<item name="android:enabled">true</item>
</style>
subTabLayout = (LinearLayout) view.findViewById(R.id.call_log_sub_tab_hw);
//init sub tab, add text view
for (int i = 0; i < mTabTitles.length; i++) {
TextView textView = new TextView(getActivity());
LogUtil.d("CallLogFragmentHw.setupView()", "tab i=" + i + "; rtl tab i=" + getRtlPosition(i));
if (getRtlPosition(i) == 0) {
textView.setBackgroundResource(R.drawable.call_log_sub_tab_bg_left_selector);
} else if (getRtlPosition(i) == mTabTitles.length - 1) {
textView.setBackgroundResource(R.drawable.call_log_sub_tab_bg_right_selector);
} else {
textView.setBackgroundResource(R.drawable.call_log_sub_tab_bg_middle_selector);
}
textView.setText(mTabTitles[i]);
textView.setGravity(Gravity.CENTER);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);
textView.setLayoutParams(lp);
//textView.setTextAppearance(R.style.CallLogSubTabTextStyle);
subTabLayout.addView(textView);
textView.setOnClickListener(this);
if (startingTab == i) {
subTabSelected(textView, true);
}
}
subTabLayout = (LinearLayout) view.findViewById(R.id.call_log_sub_tab_hw);
//init sub tab, add text view
for (int i = 0; i < mTabTitles.length; i++) {
//TextView textView = new TextView(getActivity());
TextView textView = new TextView(new ContextThemeWrapper(getActivity(), R.style.CallLogSubTabTextStyle));
LogUtil.d("CallLogFragmentHw.setupView()", "tab i=" + i + "; rtl tab i=" + getRtlPosition(i));
if (getRtlPosition(i) == 0) {
textView.setBackgroundResource(R.drawable.call_log_sub_tab_bg_left_selector);
} else if (getRtlPosition(i) == mTabTitles.length - 1) {
textView.setBackgroundResource(R.drawable.call_log_sub_tab_bg_right_selector);
} else {
textView.setBackgroundResource(R.drawable.call_log_sub_tab_bg_middle_selector);
}
textView.setText(mTabTitles[i]);
textView.setGravity(Gravity.CENTER);
//textView.setTextAppearance(R.style.CallLogSubTabTextStyle);
subTabLayout.addView(textView);
textView.setOnClickListener(this);
if (startingTab == i) {
subTabSelected(textView, true);
}
}
TextView textView = new TextView(new ContextThemeWrapper(getActivity(), R.style.CallLogSubTabTextStyle));
和在xml中使用style="R.style.CallLogSubTabTextStyle"效果相同。