Android元素在棒棒糖之前和较低api版本的文本后面带有白色背景 [英] Android elements have white background behind the text on pre-lollipop and lower api versions

查看:74
本文介绍了Android元素在棒棒糖之前和较低api版本的文本后面带有白色背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将TabLayout用于ViewPager

<android.support.design.widget.TabLayout
    android:id="@+id/tabLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabBackground="@drawable/tab_color_selector" />

但这是结果

Kitkat带有白色背景的元素

tab_color_selector有2个项目,其中state_selected="true"是默认项目.我也尝试使用像theese这样的标签,但没有成功:

tab_color_selector has 2 items with state_selected="true" and default. I also tried using tags like theese, but with no success:

android:background="@android:color/holo_blue_dark"
app:tabBackground="@android:color/holo_blue_dark"
app:tabIndicatorColor="@android:color/holo_blue_dark"

项目包括所有必需的依赖项afaik

Project includes all neccessary dependencies afaik

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.1'

也尝试过

vectorDrawables.useSupportLibrary = true

在棒棒糖和较新的api上完美工作. 元素在api 22上显示出色

Works perfectly at lollipop and newer api's. elements displays great at api 22

如您所见,tere也是工具栏菜单中的png图像,也没有透明背景.我像这样添加imade

as you can see, tere is also png image in toolbar's menu that also doesn't have transparent background. I add imade like that

toolbar.getMenu().getItem(0).setIcon(R.drawable.ic_menu);

xml:

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/colorMain"
    android:adjustViewBounds="true"
    app:popupTheme="@style/AppTheme.PopupOverlay">

我真的需要帮助.如果您对背景为何不透明有任何想法,请告诉我.谢谢

I really need help. If you have any ideas why background isn't transparent, please, let me know. Thank you

UPD:

我发现我的基本应用程序主题具有背景标签(我最近不小心添加了它们,并完全忘记了它).删除它们解决了这个问题.

I found that my base application theme has background tags (I accidentally recently added them and completely forgot about it). Removing them solved the issue.

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    ...
    <item name="android:background">@android:color/white</item>
    <item name="android:windowBackground">@android:color/white</item>
    <item name="android:colorBackground">@android:color/white</item>
</style>

但是,奇怪的是,他们只在棒棒糖之前的api上工作.

However, it is strange that they worked only on pre-lollipop api.

我想Mahesh的答案也可以.因此,我吸取了教训:检查您的样式,如果显示不正确:)

I suppose Mahesh's answer would also work. So I learned a lesson: check your styles, if something is not displayed correctly:)

推荐答案

使用自定义样式,例如

 <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabBackground="@drawable/tab_color_selector"

        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        style="@style/MyCustomTabLayout"
        />

以及您的样式文件中

<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
    <item name="tabTextAppearance">@style/MyCustomTabText</item>
    <item name="tabSelectedTextColor">@color/ColorPrimary</item>
</style>

这篇关于Android元素在棒棒糖之前和较低api版本的文本后面带有白色背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆