我需要扩展我的应用程序,该应用程序基本上代表具有Settings页面的MainActivity。我正在尝试实现WearableDrawerLayout
,但是找不到任何好的示例,而且我知道我遗漏了一些东西,因为抽屉显示为空。
activity_main.xml包含主布局以及抽屉的各个部分
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.wear.widget.drawer.WearableDrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:minHeight="50dp"
android:minWidth="50dp"
android:src="@drawable/ic_alarm"
android:tint="@color/white" />
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/screen_percentage_05"
android:text="asd"
android:textAlignment="center"
android:textColor="@color/white"
android:textStyle="bold" />
</LinearLayout>
<android.support.wear.widget.drawer.WearableNavigationDrawerView
android:id="@+id/top_navigation_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:menu="@menu/drawer_view"/>
</android.support.wear.widget.drawer.WearableDrawerLayout>
res / menu / drawer_view.xml(用于填充导航):
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_camera"
android:icon="@android:drawable/ic_menu_camera"
android:title="main" />
<item
android:id="@+id/nav_gallery"
android:icon="@android:drawable/ic_menu_gallery"
android:title="settings" />
</group>
</menu>
和MainActivity.class:
public class MainActivity extends WearableActivity {
private WearableNavigationDrawerView mWearableNavigationDrawer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setAmbientEnabled();
mWearableNavigationDrawer = (WearableNavigationDrawerView) findViewById(R.id.top_navigation_drawer);
mWearableNavigationDrawer.getController().peekDrawer();
}
}
我仍然必须将活动和框架与菜单项联系起来,但是首先,我想使抽屉包含两个项。