我在做滑动菜单。一切正常,但滑动菜单上的项目无法点击。这是我的代码。 包kz.redone.labs.hook;
public class MainActivity extends SlidingFragmentActivity {
private SlidingMenu sm;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initSlidingMenu();
}
private void initSlidingMenu(){
setBehindContentView(R.layout.activity_menu);
sm = getSlidingMenu();
sm.setMode(SlidingMenu.LEFT);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
sm.setFadeDegree(0.35f);
sm.setShadowWidthRes(R.dimen.shadow_width);
// sm.setShadowDrawable(R.drawable.shadow);
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setFadeDegree(0.35f);
sm.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
}
} 这里是MenuActivity
public class MenuActivity extends SlidingFragmentActivity implements OnClickListener {
private ListView lvMenu;
private SimpleAdapter sa;
private ArrayList<Map<String,Object>> data;
TextView tvMain;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.activity_menu, container, false);
}
public void onViewCreated(final View view, Bundle savedInstanceState) {
tvMain = (TextView) view.findViewById(R.id.tvMain);
tvMain.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stubmsg
switch (v.getId()) {
case R.id.tvMain:
Log.d("tag", "message");
Toast.makeText(this, "Main", 1500).show();
break;
default:
break;
}
}
}
这里是activity_menu.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"
tools:context=".MenuActivity" >
<TextView
android:id="@+id/tvMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
android:clickable="true"
android:text="Main"/>
<TextView
android:id="@+id/tvSetting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tvMain"
android:textSize="30dp"
android:text="Settings"/>
</RelativeLayout>
activity_main.xml仅用于textview。 谢谢!