android中的幻灯片菜单

时间:2014-10-30 05:56:16

标签: android jquery android-activity

我想要更改幻灯片菜单的背景

见下文!!!

enter image description here

我想将黑色改为其他颜色,但我无法帮助我 我的代码在这里

activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg_main" >

<com.coboltforge.slidemenu.SlideMenu
    android:id="@+id/slideMenu"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >


</com.coboltforge.slidemenu.SlideMenu>

<TextView
    android:id="@+id/textView1"
     android:background="@drawable/bg_top" />

MainActivity.java:

import com.coboltforge.slidemenu.SlideMenu;
import com.coboltforge.slidemenu.SlideMenu.SlideMenuItem;
import com.coboltforge.slidemenu.SlideMenuInterface.OnSlideMenuItemClickListener;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends Activity implements OnSlideMenuItemClickListener {

    private SlideMenu slidemenu;
    private final static int MYITEMID = 42;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        /*
         * There are two ways to add the slide menu: 
         * From code or to inflate it from XML (then you have to declare it in the activities layout XML)
         */
        // this is from code. no XML declaration necessary, but you won't get state restored after rotation.
//      slidemenu = new SlideMenu(this, R.menu.slide, this, 333);
        // this inflates the menu from XML. open/closed state will be restored after rotation, but you'll have to call init.
        slidemenu = (SlideMenu) findViewById(R.id.slideMenu);
        slidemenu.init(this, R.menu.slide, this, 333);

        // this can set the menu to initially shown instead of hidden
//      slidemenu.setAsShown(); 

        // set optional header image
        slidemenu.setHeaderImage(R.drawable.headerbanner);

        // this demonstrates how to dynamically add menu items
        SlideMenuItem item = new SlideMenuItem();
        item.id = MYITEMID;
        item.icon = getResources().getDrawable(R.drawable.ic_launcher);
        item.label = "Dynamically added item";
        slidemenu.addMenuItem(item);

        // connect the fallback button in case there is no ActionBar
        Button b = (Button) findViewById(R.id.buttonMenu);
        b.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                slidemenu.show();
            }
        }); 
    }       
}

这很简单而优雅:https://github.com/akotoe/android-slide-out-menu.git

1 个答案:

答案 0 :(得分:0)

只需在您的可绘制文件夹中创建一个名为&#39; background&#39;的新文件,然后输入您想要的XML样式  快速举例:                                                                            

然后在抽屉XML中引用这个新文件     机器人:背景=&#34; @可绘制/背景&#34;

希望有所帮助!

相关问题