Đây là câu hỏi tràn ngăn xếp đầu tiên của tôi. Hãy đi với tôi nếu tôi không thêm đủ hoặc tôi thêm quá nhiều chi tiết.Trình đơn tràn trên Android được đặt ở trên thanh tác vụ/thanh công cụ?
Tôi đang cố gắng để trình đơn mục bổ sung xuất hiện bên dưới thanh trên cùng trong ứng dụng của mình. Khi tôi đang sử dụng chủ đề Holo, nó đã làm điều này tốt, nhưng tôi đang cố gắng để ứng dụng của tôi sử dụng thiết kế material design bằng thư viện appcompat v7.
Vì vậy, chủ đề của tôi bây giờ kéo dài từ AppCompat:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/ucla_blue</item>
<item name="colorAccent">@color/caldroid_white</item>
<item name="android:actionMenuTextColor">@color/caldroid_black</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
</resources>
Và điều này đúng không áp dụng các chủ đề thiết kế tài liệu vào thanh công cụ của tôi trong cách bố trí này:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linearlayout_root_main"
android:layout_height="match_parent"
android:layout_width="match_parent">
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_height="match_parent"
android:layout_width="match_parent"
tools:context="com.ucla.ieee.app.MainActivity">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?attr/colorPrimary"
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:id="@+id/container"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
</LinearLayout>
<!-- The navigation drawer -->
<fragment
android:id="@+id/navigation_drawer"
android:layout_gravity="start"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:layout_width="@dimen/navigation_drawer_width"
android:name="navigation.NavigationDrawerFragment"
tools:layout="@layout/fragment_navigation_drawer"/>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
Nhưng đối với một số lý do, menu Tôi thổi phồng trong onCreateOptionsMenu xuất hiện ở vị trí sai. Rõ ràng tôi không thể đăng hình ảnh nhưng về cơ bản menu tràn bao gồm thanh công cụ thay vì xuất hiện ngay bên dưới thanh công cụ. Điều này bắt đầu xảy ra khi tôi sử dụng "Theme.AppCompat" đầu tiên trong một ActionBar bình thường và thậm chí bây giờ với một Thanh công cụ.
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
switch (selected) {
case FRONT_PAGE:
toolbar.inflateMenu(R.menu.main_settings);
return false;
case ANNOUNCEMENTS:
toolbar.inflateMenu(R.menu.refresh_settings);
return false;
case MEMBERSHIP:
toolbar.inflateMenu(R.menu.edit_member);
return false;
case CALENDAR:
toolbar.inflateMenu(R.menu.refresh_settings);
return false;
case POINTS_REWARDS:
toolbar.inflateMenu(R.menu.main_settings);
return false;
case HELP:
toolbar.inflateMenu(R.menu.main_settings);
return false;
default:
toolbar.inflateMenu(R.menu.main_settings);
}
Dường như không ai tìm thấy điều này, tôi hy vọng ai đó có thể giúp tôi tìm ra điều này! Cảm ơn!
Dưới đây là một ví dụ về một trong các menu của tôi:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.ucla_ieee.app.MainActivity">
<item android:id="@+id/action_refresh"
android:title="@string/action_refresh"
app:showAsAction="never" />
</menu>
Cảm ơn nhưng tôi đã làm điều này trong hoạt động chính của mình. Nó không phải là trình đơn không hoạt động, nó chỉ có vẻ sai: http://i.imgur.com/0ybW1A9.png – Tania
Cập nhật câu trả lời của tôi cho ảnh chụp màn hình của bạn: những gì bạn đang thấy là một menu Material Design. – ianhanniballake
Oh darn, đoán các ứng dụng tôi đã thực hiện Material Design đã cho tôi ý tưởng sai lầm. Cảm ơn!! – Tania