android – 没有Actionbar的导航栏

前端之家收集整理的这篇文章主要介绍了android – 没有Actionbar的导航栏前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
搜索了许多网站(stackoverflow),但是不了解如何在没有操作栏的情况下实现导航栏.我知道这个问题已经在这里被问到,但没有一个正确的解释和代码.我是 Android开发中的初学者,所以任何人都可以用代码解释我如何使没有动作栏的导航栏

提前致谢!

解决方法

Hi,There is no relation between navigation drawer and action bar try this code it will help you.

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<FrameLayout
    android:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</FrameLayout>

<ListView
    android:id="@+id/drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="#FFF"
    android:choiceMode="singleChoice"/>

java code is here

public class MainActivity extends Activity {
final String[] data ={"one","two","three"};

@Override
protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);

     ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,data);

     final DrawerLayout drawer = (DrawerLayout)findViewById(R.id.drawer_layout);
     final ListView navList = (ListView) findViewById(R.id.drawer);
     navList.setAdapter(adapter);
     navList.setOnItemClickListener(new OnItemClickListener(){
             @Override
             public void onItemClick(AdapterView<?> parent,View view,final int pos,long id){
                     drawer.setDrawerListener( new DrawerLayout.SimpleDrawerListener(){
                             @Override
                             public void onDrawerClosed(View drawerView){
                                     super.onDrawerClosed(drawerView);

                             }
                     });
                     drawer.closeDrawer(navList);
             }
     });
    }
}
原文链接:https://www.f2er.com/android/312530.html

猜你在找的Android相关文章