Android 汉堡包菜单中的Listview内部微调器

Android 汉堡包菜单中的Listview内部微调器,android,Android,我使用DrawerLayout MainActivity.java package com.example.vsoftwares.hamburgermenu; import android.content.Context; import android.content.res.Configuration; import android.os.Bundle; import android.support.v4.widget.DrawerLayout; import android.support

我使用
DrawerLayout

MainActivity.java

package com.example.vsoftwares.hamburgermenu;

import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private ListView mDrawerList,mDrawerList2;
    private DrawerLayout mDrawerLayout;
    private ArrayAdapter<String> mAdapter;
    private ActionBarDrawerToggle mDrawerToggle;
    private String mActivityTitle;

    Context ctx;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);


        // My code starts here
        mDrawerList = (ListView)findViewById(R.id.navList); //  changed listview to textview

        mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
        mActivityTitle = getTitle().toString();

        ActionBar actionBar = getSupportActionBar();
        addDrawerItems();
        setupDrawer();
        if (actionBar != null)
        {
            //actionBar.setTitle("My App Title");
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setHomeButtonEnabled(true);
            //getSupportActionBar().setDisplayShowHomeEnabled(true);
        }
        // ends here
    }

    // MY DRAWER CODE STARTS HERE
    private void addDrawerItems() {
        String[] osArray = { "iOS", "Windows", "OS X", "Linux" };


       mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, osArray);
        mDrawerList.setAdapter(mAdapter);


        mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(MainActivity.this, "have to add content", Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void setupDrawer() {
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) {

            /** Called when a drawer has settled in a completely open state. */
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                //  getSupportActionBar().setTitle("Navigation!");
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }

            /** Called when a drawer has settled in a completely closed state. */
            public void onDrawerClosed(View view) {
                super.onDrawerClosed(view);
                // getSupportActionBar().setTitle(mActivityTitle);
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }
        };

        mDrawerToggle.setDrawerIndicatorEnabled(true);
        mDrawerLayout.setDrawerListener(mDrawerToggle);
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        // Sync the toggle state after onRestoreInstanceState has occurred.
        mDrawerToggle.syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        mDrawerToggle.onConfigurationChanged(newConfig);
    }
    // ENDS HERE
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }
        // Activate the navigation drawer toggle
        if (mDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
package com.example.vsoftware.hamburgermenu;
导入android.content.Context;
导入android.content.res.Configuration;
导入android.os.Bundle;
导入android.support.v4.widget.DrawerLayout;
导入android.support.v7.app.ActionBar;
导入android.support.v7.app.ActionBarDrawerToggle;
导入android.support.v7.app.AppActivity;
导入android.support.v7.widget.Toolbar;
导入android.view.view;
导入android.view.Menu;
导入android.view.MenuItem;
导入android.widget.AdapterView;
导入android.widget.ArrayAdapter;
导入android.widget.ListView;
导入android.widget.Toast;
公共类MainActivity扩展了AppCompatActivity{
私有列表视图mDrawerList,mDrawerList2;
私人抽屉布局mDrawerLayout;
私人ArrayaAdapter mAdapter;
私有操作bardrawertoggle mDrawerToggle;
私有字符串mactivitytle;
上下文ctx;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar Toolbar=(Toolbar)findViewById(R.id.Toolbar);
设置支持操作栏(工具栏);
//我的代码从这里开始
mDrawerList=(ListView)findViewById(R.id.navList);//将ListView更改为textview
mDrawerLayout=(抽屉布局)findViewById(R.id.抽屉布局);
mActivityTitle=getTitle().toString();
ActionBar ActionBar=getSupportActionBar();
addDrawerItems();
setupDrawer();
if(actionBar!=null)
{
//actionBar.setTitle(“我的应用程序标题”);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(真);
//getSupportActionBar().setDisplayShowHomeEnabled(true);
}
//到此为止
}
//我的抽屉代码从这里开始
私有void addDrawerItems(){
字符串[]osArray={“iOS”、“Windows”、“OSX”、“Linux”};
mAdapter=newarrayadapter(这是安卓.R.layout.simple\u list\u item\u 1,osArray);
mDrawerList.setAdapter(mAdapter);
mDrawerList.setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
Toast.makeText(MainActivity.this,“必须添加内容”,Toast.LENGTH_SHORT.show();
}
});
}
私有void setupDrawer(){
mDrawerToggle=newactionBarDrawerToggle(此,mDrawerLayout,R.string.drawer\u打开,R.string.drawer\u关闭){
/**当抽屉处于完全打开状态时调用*/
打开图纸上的公共空白(视图抽屉视图){
super.onDrawerOpened(抽屉视图);
//getSupportActionBar().setTitle(“导航!”);
InvalidateOptions SMenu();//创建对OnPrepareOptions SMenu()的调用
}
/**当抽屉处于完全关闭状态时调用*/
公共无效onDrawerClosed(视图){
super.onDrawerClosed(视图);
//getSupportActionBar().setTitle(mActivityTitle);
InvalidateOptions SMenu();//创建对OnPrepareOptions SMenu()的调用
}
};
mDrawerToggle.setDrawerIndicatorEnabled(true);
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
@凌驾
后期创建时受保护的空(捆绑包savedInstanceState){
super.onPostCreate(savedInstanceState);
//在onRestoreInstanceState发生后同步切换状态。
mDrawerToggle.syncState();
}
@凌驾
公共无效OnConfiguration已更改(配置newConfig){
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
//到此为止
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(右菜单菜单菜单主菜单);
返回true;
}
@凌驾
公共布尔值onOptionsItemSelected(菜单项项){
//处理操作栏项目单击此处。操作栏将
//自动处理Home/Up按钮上的点击,只要
//在AndroidManifest.xml中指定父活动时。
int id=item.getItemId();
//noinspection SimplifiableIf语句
if(id==R.id.action\u设置){
返回true;
}
//激活导航抽屉开关
如果(MDRAWERTOGLE.onOptionsItemSelected(项目)){
返回true;
}
返回super.onOptionsItemSelected(项目);
}
}
activity_main.xml

<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">


    <!-- The first child in the layout is for the main Activity UI-->
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
        tools:context=".MainActivity"
        android:background="#FF4081">


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:text="PAGE 1"
            android:textSize="24sp"
            android:gravity="center"
            android:layout_marginTop="100dp"/>



    </RelativeLayout>

    <!-- Side navigation drawer UI -->
    <ListView
        android:id="@+id/navList"
        android:layout_width="200dp"
        android:text="hello"
        android:layout_height="match_parent"
        android:textColor="#000"
        android:background="#FFFFFF"
        android:layout_gravity="left|start"
        />


</android.support.v4.widget.DrawerLayout>

我在我的代码中尝试了内部布局微调器,但它不能产生我想要的结果。请给我一些帮助。我需要它看起来更像以下内容: