gpt4 book ai didi

android更改选项卡指示器样式

转载 作者:行者123 更新时间:2023-11-30 03:05:50 24 4
gpt4 key购买 nike

这是我的风格

<style name="MyCustomTheme" parent="@style/Theme.AppCompat">
<item name="android:actionBarStyle">@style/MyActionBarTheme</item>
<item name="actionBarTabTextStyle">@style/MyActionBarTabText</item>
<item name="android:actionBarTabStyle">@style/customActionBarTabStyle</item>
<item name="actionMenuTextColor">#fff</item>
</style>
<style name="customActionBarTabStyle" parent="@style/Widget.AppCompat.ActionBar.TabView">

<!-- tab indicator -->
<item name="android:background">#ac0910</item>

<!-- Support library compatibility -->
<item name="background">@drawable/actionbar_tab_indicator</item>
</style>

我得到了这个结果: enter image description here但如果我将 xml 更改为: enter image description here

    <!-- tab indicator -->
<item name="android:background">@drawable/actionbar_tab_indicator</item>

<!-- Support library compatibility -->
<item name="background">@drawable/actionbar_tab_indicator</item>
</style>

我得到了这个结果:

这是我的@drawable/actionbar_tab_indicator

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

<!-- STATES WHEN BUTTON IS NOT PRESSED -->

<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/tab_unselected" />
<item android:state_focused="false" android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/tab_selected" />

<!-- Focused states (such as when focused with a d-pad or mouse hover) -->
<item android:state_focused="true" android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/tab_unselected_focused" />
<item android:state_focused="true" android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/tab_selected_focused" />


<!-- STATES WHEN BUTTON IS PRESSED -->

<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false"
android:state_pressed="true"
android:drawable="@drawable/tab_unselected_pressed" />
<item android:state_focused="false" android:state_selected="true"
android:state_pressed="true"
android:drawable="@drawable/tab_selected_pressed" />

<!-- Focused states (such as when focused with a d-pad or mouse hover) -->
<item android:state_focused="true" android:state_selected="false"
android:state_pressed="true"
android:drawable="@drawable/tab_unselected_pressed" />
<item android:state_focused="true" android:state_selected="true"
android:state_pressed="true"
android:drawable="@drawable/tab_selected_pressed" />
</selector>

最重要的部分是

@drawable/tab_selected_pressed@drawable/tab_unselected_pressed@drawable/tab_selected_pressed...

是像矩形和填充颜色这样的图像。这就是我虽然是指标

最佳答案

在xml中创建自定义布局

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/tab_button_drawable"
android:orientation="vertical"
android:padding="10dp" > <TextView
android:id="@+id/tab_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@drawable/text_navigator_color_drawable"
android:textSize="14dp" /></LinearLayout>

并创建一个方法,该方法将返回一个自定义 View ,而不是在定义选项卡 View 之后定义为这个

public View createTabView(final Context context, final String text) {
View view = LayoutInflater.from(context).inflate(R.layout.tab_layout,
null);
TextView tv = (TextView) view.findViewById(R.id.tab_text_view);
tv.setText(text);
return view;
}

tabSpec.setIndicator(createTabView(tabHost.getContext(),
tabWidgetTextView.getText().toString()));

关于android更改选项卡指示器样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21827128/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com