如何在Android导航抽屉中的left_drawer片段(参见链接:如何在Android导航抽屉中显示登录屏幕),我想使用按钮从主界面打开此登录屏幕,还不希望导航抽屉上出现操作栏。请有谁可以帮助我解决这个问题吗?
提前致谢!
如何在Android导航抽屉中的left_drawer片段(参见链接:如何在Android导航抽屉中显示登录屏幕),我想使用按钮从主界面打开此登录屏幕,还不希望导航抽屉上出现操作栏。请有谁可以帮助我解决这个问题吗?
提前致谢!
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- This is how your main page will look, just 2 buttons -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:onClick="onLeft"
android:text="left" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:onClick="onRight"
android:text="right" />
</RelativeLayout>
<!-- Left Drawrer -->
<RelativeLayout
android:id="@+id/whatYouWantInLeftDrawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start" >
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_dark" />
<!-- you can have many more widgets here like buttons or labels -->
</RelativeLayout>
<!-- Right Drawrer -->
<RelativeLayout
android:id="@+id/whatYouWantInRightDrawer"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="right" >
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_green_light" />
<!-- you can have many more widgets here like buttons or labels -->
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
然后将您的活动设置为以下内容:
public class MainActivity extends Activity {
RelativeLayout leftRL;
RelativeLayout rightRL;
DrawerLayout drawerLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// I'm removing the ActionBar.
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
leftRL = (RelativeLayout)findViewById(R.id.whatYouWantInLeftDrawer);
rightRL = (RelativeLayout)findViewById(R.id.whatYouWantInRightDrawer);
drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
}
public void onLeft(View view)
{
drawerLayout.openDrawer(leftRL);
}
public void onRight(View view)
{
drawerLayout.openDrawer(rightRL);
}
}
你可以使用导航抽屉。非常容易实现,看起来非常专业。不要在导航抽屉中放置列表视图,而是创建另一个布局,并在导航抽屉激活时填充该布局。你可以在这里查看有关导航抽屉的信息。
你会发现许多方法来拥有一个滑动抽屉。但你的问题将是创建一个自定义布局并将其填充到导航抽屉中。
祝你好运!