私の活動からナビゲーション・ドロワーを呼び出そうとしましたが、何も起こりませんでした。私はActionBarDrawerToggleを使用しましたか?ボタンでナビゲーション・ドロワーを開く
public class SettingsDrawer {
Context mContext;
ArrayList<SettingsDrawerItem> items;
ListView listView;
ImageView logo;
DrawerLayout mDrawerLayout;
public SettingsDrawer(Context context) {
this.mContext = context;
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.settings_drawer_layout, null);
mDrawerLayout = (DrawerLayout) view.findViewById(R.id.drawerLayout);
listView = (ListView) view.findViewById(R.id.settingsList);
logo = (ImageView) view.findViewById(R.id.logo);
DrawListAdapter adapter = new DrawListAdapter(mContext, items);
listView.setAdapter(adapter);
mDrawerLayout.openDrawer(Gravity.LEFT);
}
そして、私の活動の
public class Activity extends AppCompatActivity{
Button settingsDrawerButton =(Button)findViewById(R.id.settingsDrawer);
settingsDrawerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i(TAG,"settings drawer click!");
SettingsDrawer s = new SettingsDrawer(Activity.this);
}
});
}
UPDATE:XML私はそのように設定してみました:mDrawerLayout.openDrawer(drawerPane)が、アイブ氏は、同様にClassCastExceptionを得ました。 DrawerLayoutはRelativeLayoutにキャストできないので、かなり控えめだと思っていました。
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="280dp"
android:layout_height="match_parent"
android:id="@+id/drawerPane"
android:layout_gravity="start">
<RelativeLayout
android:id="@+id/logoBox"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/material_blue_grey_800"
android:padding="8dp" >
<ImageView
android:id="@+id/logo"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_centerInParent="true"/>
</RelativeLayout>
<ListView
android:id="@+id/settingsList"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_below="@+id/logoBox"
android:choiceMode="singleChoice"
android:background="#ffffffff" />
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
この行を追加するmDrawerLayout.openDrawer(listView); – user3068659