我通过跟随this tuts做了普通的抽屉。但我需要使用Android最新技术实现自定义抽屉,如下图所示,以显示最新的用户通知计数(如果有的话)。
实际上我需要以下钩子形状。
抽屉打开状态
抽屉关闭状态
我尝试了9张补丁图片但是当关闭抽屉时,钩子的颜色更新为红色。我完全糊涂了。非常感谢。
答案 0 :(得分:0)
创建包含列表视图的RelativieLayout并添加图像按钮。并在指定使用9patch图像时更改图像。在抽屉上打开和关闭作为工具抽屉监听器,如下所示
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<ListView
android:id="@+id/lv_list"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:background="@drawable/bg"
android:divider="@android:color/black"
android:dividerHeight="1dp" />
<ImageButton
android:layout_width="wrap_content"
android:id="@+id/drawer_slider"
android:layout_height="wrap_content"
android:background="@drawable/icon_slider_indicator"
android:layout_alignParentEnd="true"
android:layout_centerInParent="true"/>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
实现在图像按钮中更改图像的Listener
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
//update your image view of imagebutton
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
//update your image on imagebutton
}
};
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);