为什么我的抽屉菜单看起来是黑色的?

用户名

我创建了一个“抽屉菜单示例”,以下是我的源代码,

public class DrawerActivity extends Activity 
{
    private String [] menuOptions = new String[] { "Option1", "Option2","Option3" };
    private DrawerLayout mDrawerLayout;
    private ListView mDrawerList;
    private ActionBarDrawerToggle mDrawerToggle;
    private ArrayAdapter<String> adapter; 


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

        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerList = (ListView) findViewById(R.id.left_drawer);

        adapter = new ArrayAdapter<String> ( this, android.R.layout.simple_list_item_1, menuOptions );
        mDrawerList.setAdapter(adapter);
        mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setHomeButtonEnabled(true);

        // ActionBarDrawerToggle ties together the the proper interactions
        // between the sliding drawer and the action bar app icon
        mDrawerToggle = new ActionBarDrawerToggle(
                this,                  /* host Activity */
                mDrawerLayout,         /* DrawerLayout object */
                R.drawable.ic_drawer,  /* nav drawer image to replace 'Up' caret */
                R.string.drawer_open,  /* "open drawer" description for accessibility */
                R.string.drawer_close  /* "close drawer" description for accessibility */
                ) 
        {
            public void onDrawerClosed(View view) 
            {
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }

            public void onDrawerOpened(View drawerView) 
            {
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }
        };      

        mDrawerLayout.setDrawerListener(mDrawerToggle);

    }

    /**
     * When using the ActionBarDrawerToggle, you must call it during
     * onPostCreate() and onConfigurationChanged()...
     */

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

    private class DrawerItemClickListener implements ListView.OnItemClickListener
    {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int position,long arg3) 
        {
            // update selected item and title, then close the drawer
            mDrawerList.setItemChecked(position, true);
            mDrawerLayout.closeDrawer(mDrawerList);
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) 
    {
        // The action bar home/up action should open or close the drawer.
        // ActionBarDrawerToggle will take care of this.
        if (mDrawerToggle.onOptionsItemSelected(item)) 
        {
            return true;
        }
        else return false;
    }
}

这是我的AndroidManifest.xml文件的代码

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.drawerdemo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".DrawerActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

代码工作正常,但我的“抽屉”菜单显示为黑色,请参见图片

http://i.stack.imgur.com/toEfm.png

你能告诉我我在哪里做错了吗?

Shanmugapriyan M
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <include layout="@layout/action_bar_header" />

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <!-- The main content view -->

        <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
        <!-- The navigation drawer -->

        <LinearLayout
            android:id="@+id/drawer"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="@android:color/darker_gray"
            android:orientation="vertical" >
        </LinearLayout>
    </android.support.v4.widget.DrawerLayout>

</LinearLayout>

更改菜单布局的背景颜色

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为什么我的滚动条看起来很古怪?

来自分类Dev

为什么我的Xubuntu LibreOffice看起来很难看?

来自分类Dev

为什么我的漏斗看起来像这样?

来自分类Dev

为什么我的WinForms控件看起来平坦?

来自分类Dev

为什么我的Xubuntu LibreOffice看起来很难看?

来自分类Dev

为什么我的滚动条看起来很古怪?

来自分类Dev

为什么我的字体看起来不同?

来自分类Dev

为什么我的TreeView看起来像这样?

来自分类Dev

为什么我的谷歌图表看起来不对

来自分类Dev

为什么按钮看起来很奇怪?

来自分类Dev

为什么输出看起来不同?

来自分类Dev

为什么按钮看起来很奇怪?

来自分类Dev

为什么固定菜单的内页和首页看起来不同

来自分类Dev

为什么当我启动我的程序时我的外观和感觉看起来很奇怪?

来自分类Dev

为什么我的CSV看起来不像我需要的样子?

来自分类Dev

为什么我的iOS字体看起来非常像素化?iOS7的最佳字体?

来自分类Dev

为什么我的JavaFX窗口到处看起来都不一样?

来自分类Dev

为什么我的PDF的RMagick渲染看起来如此糟糕?

来自分类Dev

为什么我的CSS与您的CSS看起来有所不同?

来自分类Dev

为什么我的粘贴图像在LibreOffice Writer中看起来像裁剪的?

来自分类Dev

为什么看起来好像我的物体被摧毁了两次?

来自分类Dev

为什么我的asp.net项目看起来像引用未解决?

来自分类Dev

为什么我使用matplotlib的曲线拟合图看起来模糊了?

来自分类Dev

为什么在Chrome(仅在Windows中)和Firefox中我的样式规则看起来不同?

来自分类Dev

为什么我的应用程序在iPad上看起来是模拟的?

来自分类Dev

为什么我的SVG看起来不像波纹(关于feDisplacementMap过滤器)

来自分类Dev

为什么我的毫秒在JS秒表中看起来不对

来自分类Dev

我的Mandelbrot看起来不应该。有人知道为什么吗?

来自分类Dev

为什么我的函数返回的列表结果看起来很滑稽?

Related 相关文章

  1. 1

    为什么我的滚动条看起来很古怪?

  2. 2

    为什么我的Xubuntu LibreOffice看起来很难看?

  3. 3

    为什么我的漏斗看起来像这样?

  4. 4

    为什么我的WinForms控件看起来平坦?

  5. 5

    为什么我的Xubuntu LibreOffice看起来很难看?

  6. 6

    为什么我的滚动条看起来很古怪?

  7. 7

    为什么我的字体看起来不同?

  8. 8

    为什么我的TreeView看起来像这样?

  9. 9

    为什么我的谷歌图表看起来不对

  10. 10

    为什么按钮看起来很奇怪?

  11. 11

    为什么输出看起来不同?

  12. 12

    为什么按钮看起来很奇怪?

  13. 13

    为什么固定菜单的内页和首页看起来不同

  14. 14

    为什么当我启动我的程序时我的外观和感觉看起来很奇怪?

  15. 15

    为什么我的CSV看起来不像我需要的样子?

  16. 16

    为什么我的iOS字体看起来非常像素化?iOS7的最佳字体?

  17. 17

    为什么我的JavaFX窗口到处看起来都不一样?

  18. 18

    为什么我的PDF的RMagick渲染看起来如此糟糕?

  19. 19

    为什么我的CSS与您的CSS看起来有所不同?

  20. 20

    为什么我的粘贴图像在LibreOffice Writer中看起来像裁剪的?

  21. 21

    为什么看起来好像我的物体被摧毁了两次?

  22. 22

    为什么我的asp.net项目看起来像引用未解决?

  23. 23

    为什么我使用matplotlib的曲线拟合图看起来模糊了?

  24. 24

    为什么在Chrome(仅在Windows中)和Firefox中我的样式规则看起来不同?

  25. 25

    为什么我的应用程序在iPad上看起来是模拟的?

  26. 26

    为什么我的SVG看起来不像波纹(关于feDisplacementMap过滤器)

  27. 27

    为什么我的毫秒在JS秒表中看起来不对

  28. 28

    我的Mandelbrot看起来不应该。有人知道为什么吗?

  29. 29

    为什么我的函数返回的列表结果看起来很滑稽?

热门标签

归档