我正在制作一個應(yīng)用程序,其中我沒有使用操作欄主題,現(xiàn)在我想要的是當(dāng)我單擊 Imagebutton 時應(yīng)該顯示導(dǎo)航抽屜。我試過制作抽屜,但不知道如何在點擊導(dǎo)航抽屜上制作圖像按鈕。 <ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/backbutton"
android:layout_marginTop="35dp"
android:layout_alignParentTop="true"
android:id="@+id/backbutton"/>沒有錯誤,因為我還沒有開始任何事情,請指導(dǎo)我。
1 回答

繁星點點滴滴
TA貢獻(xiàn)1803條經(jīng)驗 獲得超3個贊
只需將 an 添加onClickListener到ImageButton單擊時打開抽屜的 。以下幾行應(yīng)該可以解決問題。
final DrawerLayout drawer = findViewById(R.id.drawer_layout);
ImageButton imageButton = findViewById(R.id.backbutton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
drawer.openDrawer(GravityCompat.START);
}
});
添加回答
舉報
0/150
提交
取消