我在没有Listview
项目的情况下使用Android NavigationDrawer进入幻灯片菜单,在创建和更改幻灯片菜单后,项目不会单击并且无法处理单击,例如下面的代码是我的XML布局:
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/create_new_waybill"
android:gravity="center_vertical"
android:orientation="vertical"
android:layout_margin="5dp"
android:clickable="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_add_waybill"
android:layout_gravity="center"/>
<com.sample.app.Widgets.TextViewStyle
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="@dimen/normal_text_size"
android:text="@string/slidemenu_waybill"
app:fonttype="mjbeirut"
android:textColor="#000000"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/mainViewFragments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
在此XML中,我想在点击Toast
id后显示create_new_waybill
。
我的活动
public class ActivityMain extends FragmentActivity {
private DrawerLayout mDrawerLayout;
private LinearLayout mSlideMenuContainer;
private ActionBarDrawerToggle mDrawerToggle;
private String[] items;
private UiFiller uiFiller;
private int currentSelectedSlideMenuItem;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
G.currentActivity = this;
/* Getting reference to the DrawerLayout */
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mSlideMenuContainer = (LinearLayout) findViewById(R.id.slide_menu);
LinearLayout create_new_waybill = (LinearLayout) findViewById(R.id.create_new_waybill);
create_new_waybill.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.e("ffffffffffff","aaaaaaa");
}
});
/* Initials UI widgets */
uiFiller = new UiFiller(getWindow().getDecorView());
/* Setting default fragment */
currentSelectedSlideMenuItem = 0;
updateFragment(currentSelectedSlideMenuItem);
}
}
答案 0 :(得分:0)
尝试为ImageView
和TextViewStyle
设置这3个属性:
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"
并替换Log.e("ffffffffffff","aaaaaaa");
使用:
Toast.makeText(view.getContext(), "Some text", Toast.LENGTH_SHORT).show();