我使用Android Studio的基本模板中的導航抽屜啓動了一個項目。我做的唯一修改是將其顯示爲永久性的,以便擁有平板電腦/電視佈局。選定項目後永久導航視圖鬆散焦點
要做到這一點,我所做的唯一修改是在xml佈局中。這使得NavigationView始終可見。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Content will come here" />
</LinearLayout>
</LinearLayout>
我也把項目放在Github上,所以任何人都可以測試它。當我開始選擇在與d-墊在抽屜項目
項目DEMO在GitHub上
https://github.com/ChristopheVersieux/NavFocus
發生了什麼
我的問題來了。 選擇一個項目後,焦點完全丟失。試圖讓回到抽屜,並得到重點似乎很努力,我有左/右箭頭
的期望是什麼試幾次:
抽屜應該保持焦點,或重點應該是很容易帶回抽屜。
我的嘗試:
我最簡單的想法是迫使抽屜得到再次集中,但是這個代碼不改變任何東西:
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
menuItem.setChecked(true);
//This is where I will replace the Fragments in the right area.
navigationView.clearFocus();
navigationView.requestFocus();
return true;
}
});
感謝很多關於你的幫幫我。
您可以上傳圖片以獲得預期的效果和發生的情況嗎? –