Slidingmenu使用的简单操作
作者:互联网
很久没有使用常见的一些库了,记录一下。在使用这个里面遇到了一个坑:
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/view/ViewConfigurationCom
删除重新添加就可以了。
package com.example.slidingmenu;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SlidingMenu menu=new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
menu.attachToActivity(this,SlidingMenu.SLIDING_WINDOW);
menu.setBehindOffset(200);
menu.setMenu(R.layout.menu_item);
menu.setOnOpenedListener(new SlidingMenu.OnOpenedListener() {
@Override
public void onOpened() {
Toast.makeText(MainActivity.this, "打开了", Toast.LENGTH_SHORT).show();
}
});
//关闭监听
menu.setOnClosedListener(new SlidingMenu.OnClosedListener() {
@Override
public void onClosed() {
Toast.makeText(MainActivity.this, "关闭了", Toast.LENGTH_SHORT).show();
}
});
}
}
//mainActivity xml
<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="#ff0000"
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="com.example.slidingmenu.MainActivity" >
</RelativeLayout>
//item xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:background="#00ff00"
android:layout_height="match_parent"
tools:context="com.example.slidingmenu.MainActivity" >
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/btn1"/>
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/btn2"/>
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/btn3"/>
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/btn4"/>
</LinearLayout>
标签:Slidingmenu,SlidingMenu,layout,menu,import,简单,操作,android,com 来源: https://blog.csdn.net/kingmasterlife/article/details/100919231