Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何实现Android应用程序的滑动菜单?(闭门)_Android_Menu - Fatal编程技术网

如何实现Android应用程序的滑动菜单?(闭门)

如何实现Android应用程序的滑动菜单?(闭门),android,menu,Android,Menu,很抱歉,我知道它已经被问了很多次,但我没有找到一个滑动菜单的好教程 新尝试(3) 我用一个(简单的)列表视图进行了尝试: 1.像谷歌一样尝试 谷歌风格& 完成: 问题 ->自从我将其放入链接3这样的外部类后,它就开始工作了。 ->也可以使用AppIcon打开菜单,但不再工作 ->我只想更改活动(可能:Fragments(?) ActivityMain&其他人看起来是这样的: private static Context context; @Override protected void

很抱歉,我知道它已经被问了很多次,但我没有找到一个滑动菜单的好教程

新尝试(3) 我用一个(简单的)列表视图进行了尝试:
1.像谷歌一样尝试


谷歌风格&
完成:

问题 ->自从我将其放入链接3这样的外部类后,它就开始工作了。
->也可以使用AppIcon打开菜单,但不再工作
->我只想更改活动(可能:
Fragment
s(?)

ActivityMain&其他人看起来是这样的:

private static Context context;

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

@Override
public void onStart(){
    super.onStart();

    final String[] values = getResources().getStringArray(R.array.nav_drawer_items);

    ((ListView) findViewById(R.id.left_drawer)).setAdapter(new ArrayAdapter<String>(this, R.layout.menu_list_item, values));

    NavigationDrawerSetup nds=new NavigationDrawerSetup((ListView) findViewById(R.id.left_drawer), (DrawerLayout) findViewById(R.id.drawer_layout), values, getActionBar(), context);

    nds.confiugreDrawer();
}
像这样试试

public class MainActivity extends Activity {

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

        final SlidingMenu menu = new SlidingMenu(this);
        menu.setMode(SlidingMenu.LEFT);
        menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
        menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
        menu.setFadeDegree(0.5f);
        menu.attachToActivity(MainActivity.this, SlidingMenu.SLIDING_CONTENT);
        menu.setMenu(R.layout.activity_menu);
    }
活动菜单.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" >

<!-- The main content view -->

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/popuptestview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="20dp"
        android:text="@string/view" />

    <EditText
        android:id="@+id/et_subnetTest"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/popuptestview"
        android:layout_alignParentRight="true"
        android:ems="10"
        android:gravity="right"
        android:hint="@string/app_name"
        android:inputType="textEmailAddress" >

        <requestFocus />
    </EditText>
</RelativeLayout>

<!-- The navigation drawer -->

<ListView
    android:id="@+id/left_drawer"
    android:layout_width="200dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"
    android:fadingEdge="vertical" />

    </android.support.v4.widget.DrawerLayout>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/listitem"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:padding="@dimen/activity_vertical_margin"
android:textSize="@dimen/menu" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00FFFF"
    tools:context=".MainActivity" >

</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    tools:context=".MainActivity" >
</RelativeLayout>

这是您的activitymain.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" >

<!-- The main content view -->

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/popuptestview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="20dp"
        android:text="@string/view" />

    <EditText
        android:id="@+id/et_subnetTest"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/popuptestview"
        android:layout_alignParentRight="true"
        android:ems="10"
        android:gravity="right"
        android:hint="@string/app_name"
        android:inputType="textEmailAddress" >

        <requestFocus />
    </EditText>
</RelativeLayout>

<!-- The navigation drawer -->

<ListView
    android:id="@+id/left_drawer"
    android:layout_width="200dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"
    android:fadingEdge="vertical" />

    </android.support.v4.widget.DrawerLayout>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/listitem"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:padding="@dimen/activity_vertical_margin"
android:textSize="@dimen/menu" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00FFFF"
    tools:context=".MainActivity" >

</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    tools:context=".MainActivity" >
</RelativeLayout>


完成此操作后,只需向左滑动屏幕,您将获得另一个活动。

为什么不使用NavigationDrawer?我在哪里获得它谷歌股票?-我不懂演示…是的,谷歌的股票。我试过这样做,但我不知道最重要的元素是什么&它不起作用……还有像演示应用程序这样的菜单,比如切换颜色?是的,你还需要什么,你可以根据需要自定义你的活动菜单。当然-在活动菜单中,我可以设置我的菜单样式?看上面,新尝试第52行是setAdapter(),它正在工作。。。现在我想给它一个布局