简体   繁体   English

Android 4片段操作栏未显示

[英]Android 4 Fragment Action Bar Not Showing

I use Linear Layout inside a Relative Layout. 我在相对布局中使用线性布局。 Because of this, the action bar is not showing up. 因此,操作栏不会显示。 It works fine both on Android 5 and 6. This problem only occurs in Android 4. Could you please help me? 它在Android 5和6上都可以正常工作。仅在Android 4中会出现此问题。请您能帮帮我吗?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.blabla">
<LinearLayout
    android:paddingTop="60dp"
    android:paddingLeft="@dimen/act_left"
    android:paddingRight="10dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:background="@color/background_gray_soft">
....
</LinearLayout>
</RelativeLayout>

For those who uses FrameLayouts with Fragments in ICS, do not change your background with 对于那些在ICS中使用带有分片的FrameLayouts的人,请不要使用

android:backgound="..."

It makes the Toolbar color same with your background.(I have no idea why. Still trying to figure it out.) 它使工具栏的颜色与您的背景相同。(我不知道为什么。仍在尝试找出它。)

You need to check your API version in your Java code and set the background color there. 您需要在Java代码中检查API版本并在其中设置背景颜色。

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            FrameLayout frameLayout = (FrameLayout) findViewById(R.id.fragment_container);
            frameLayout.setBackgroundColor(getResources().getColor(R.color.background_gray_soft));
        }

There is only one problem left and that could not be solved with this method. 只剩下一个问题,用这种方法无法解决。

If you want to have a special background color in ICS(I only encountered this problem with Fragments), how will you set that? 如果您想在ICS中使用特殊的背景色(我在Fragments中仅遇到此问题),您将如何设置呢?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM