AppCompat不适用于Xperia Z2

时间:2016-01-07 12:43:51

标签: android android-theme

我有一个问题,我用Theme.AppCompat.NoActionBar创建了一个应用程序,但是在Xperia Z2上不起作用。在这款手机上只有 背景颜色 而没有别的,但在其他手机上却有效。

当我使用holo theme,时没关系,但我使用的是工具栏,需要setSupportActionBar();

截图:

enter image description here

1 个答案:

答案 0 :(得分:2)

以下是Toolbar的示例:

<android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?actionBarSize"
                app:layout_collapseMode="pin" />

您应该在活动中使用以上代码。(如果您使用带有NoActionbar的AppCompat)

示例:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/ampertech_gray">

<android.support.v7.widget.Toolbar
                android:id="@+id/tool_bar"
                android:layout_width="match_parent"
                android:layout_height="?actionBarSize"
                app:layout_collapseMode="pin" />
<!-- Here is the Toolbar -->

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/indicator">

    </android.support.v4.view.ViewPager>

    <com.viewpagerindicator.CirclePageIndicator
        android:id="@+id/indicator"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_above="@+id/btnEndTutorial"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"/>

    <Button
        android:id="@+id/btnEndTutorial"
        style="@style/Widget.AppCompat.Button.ButtonBar.AlertDialog"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="10dp"
        android:text="@string/jump"/>

</RelativeLayout>

Actionbar已弃用。请AppCompat

工具栏声明示例:

Toolbar toolbar = (Toolbar) findViewById(R.id.tool_bar); // Attaching the layout to the toolbar object
            setSupportActionBar(toolbar); // Setting toolbar as the ActionBar with setSupportActionBar() call

请参阅:http://developer.android.com/training/material/theme.html