android – 使用没有TitleBar或ActionBar的导航栏

我正在为这个应用程序添加一个导航栏,我正在开发,我已经浏览了互联网;论坛,stackoverflow,android开发人员文档,还没有找到一个很好的答案.

我知道有可能这样做,而不使用这些东西.我想知道是怎么回事NsMenuAdapter模型使用一个标题,然后有这些功能

getActionBar().setdisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);

其中显然是寻找一个动作栏.我尝试了几个没有工作的模型,我刚刚完成的大型模块位于这里How to Add icons adjacent to titles for Android Navigation Drawer(这与我以下的链接相关,该项目来自gitHub这里是https://github.com/gabrielemariotti/androiddev/tree/master/NavigationDrawer).现在的关键是,我正在使用一个自定义的布局(即相对布局与线性布局混合),我真的很失去了我的下一步应该是为了让这个工作.

Sidenote:当我的main_activity.xml(导航抽屉的实现)中只有ListView时,它正好像想象的那样滑出来.但是我不知道如何用数据填充它.我基本上需要3个标题,它们将具有可点击的导航元素,其中包含元素旁边的图标.

我转向这个模型,大部分我的见解如何通过相对布局http://gmariotti.blogspot.com/2013/05/creating-navigation-drawer.html这样做但是他们使用动作/标题栏,这是真正的扔给我一个循环.

解决方法

实际上很简单比ActionBar更容易.我正在用最简单的布局写出答案

使你的xml像这样:

<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 Drawer -->
    <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 Drawer -->
    <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);
    }
}

而已.希望有帮助

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...