0
A
回答
2
是的,這是可能的。只要看看示例應用程序。這包含CustomContainerActivity
,展示了你可以如何有一個Drawer
是低於Toolbar
public class CustomContainerActivity extends AppCompatActivity {
//save our header or result
private Drawer result = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample_custom_container_dark_toolbar);
// Handle Toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(R.string.drawer_item_custom_container_drawer);
//Create the drawer
result = new DrawerBuilder(this)
//this layout have to contain child layouts
.withRootView(R.id.drawer_container)
.withToolbar(toolbar)
.withActionBarDrawerToggleAnimated(true)
.addDrawerItems(
new PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home),
new PrimaryDrawerItem().withName(R.string.drawer_item_free_play).withIcon(FontAwesome.Icon.faw_gamepad),
new PrimaryDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye),
new SectionDrawerItem().withName(R.string.drawer_item_section_header),
new SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cog),
new SecondaryDrawerItem().withName(R.string.drawer_item_help).withIcon(FontAwesome.Icon.faw_question).withEnabled(false),
new SecondaryDrawerItem().withName(R.string.drawer_item_open_source).withIcon(FontAwesome.Icon.faw_github),
new SecondaryDrawerItem().withName(R.string.drawer_item_contact).withIcon(FontAwesome.Icon.faw_bullhorn)
)
.withSavedInstance(savedInstanceState)
.build();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
//add the values which need to be saved from the drawer to the bundle
outState = result.saveInstanceState(outState);
super.onSaveInstanceState(outState);
}
@Override
public void onBackPressed() {
//handle the back press :D close the drawer first and if the drawer is closed close the activity
if (result != null && result.isDrawerOpen()) {
result.closeDrawer();
} else {
super.onBackPressed();
}
}
}
還要注意這是在這個Activity
使用不同的XML佈局。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:elevation="4dp" />
<!-- the layout which will contain (host) the drawerLayout -->
<FrameLayout
android:layout_below="@id/toolbar"
android:id="@+id/drawer_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- the layout which will be the content of the activity (which will be hosted inside the drawer (NOT the list of the drawer)) -->
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/txtLabel"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test"
android:textSize="16sp" />
</FrameLayout>
</FrameLayout>
</RelativeLayout>
這將產生如下:
相關問題
- 1. android - actionbar不可見
- 2. ActionBar標題不可見
- 3. PowerShell打開Outlook,使可見
- 4. 使ActionBar圖標動態可見/不可見
- 5. 活動ActionBar在片段中不可見
- 6. 按鈕在ActionBar設置可見性?
- 7. 打開鏈接與可可
- 8. 如何打開與不可見的窗口一個exe?
- 9. 手動打開ActionBar導航列表
- 10. navdrawer上的活動
- 11. Android RecyclerView - 當鍵盤打開時,保持最後一個可見項目可見
- 12. 我可以在VB6中打開不可見的窗體嗎?
- 13. 可見和不可見與複選框
- 14. 打印不輸出可見
- 15. 打印僅可見DIV
- 16. 在Android上實現NavDrawer
- 17. Android ActionBar溢出菜單選項不工作時,碎片可見
- 18. 在更改標籤上更改ActionBar項目的可見性
- 19. 如何設置不同片段中ActionBar項目的可見性
- 20. 打開與gfortran
- 21. 打開與PHP
- 22. EditText自動打開軟鍵盤時使用ViewPager可見碎片
- 23. 打開可見性時字體大小發生變化
- 24. UISplitViewController - 在縱向模式下以masterViewController可見的方式打開
- 25. gwt複合打開/可見處理程序
- 26. 使用Javascript使頁面打開時圖像可見
- 27. LXC guest虛擬機不可見主機IP。打開vSwitch上橋
- 28. 當ActionMode打開時,AppCompat工具欄保持可見
- 29. 打開調試快照鏈接不可見?
- 30. 打開共享操作的不可見活動(ACTION_SEND)
這是工作。我會盡快接受答案。你太快了,謝謝你! – zatziky
好的很好:)謝謝 – mikepenz