簡體   English   中英

單個活動中的工具欄后退按鈕

[英]Toolbar back button in single activity

當我只有 1 個活動 (MainActivity) 和許多片段以及調用另一個片段的片段時,我該如何實現這個后退按鈕。 工具欄

到目前為止,我嘗試了以下操作,但我認為這僅適用於活動:

 Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setNavigationIcon(R.drawable.ic_action_navigationdrawer);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

假設您使用 Apple AppCompatActivity,那么這是我建議的動態布局工作方式。 您可以添加按鈕並在之后更改標題

   this.supportActionBar!!.displayOptions =  ActionBar.DISPLAY_SHOW_CUSTOM
        this.supportActionBar!!.setCustomView(R.layout.toolbar_title)
        val title = findViewById<TextView>(R.id.tvTitle)
        title.text = resources.getString(R.string.user_login)

作為片段后壓功能,您必須指定頁面結構。 如果您的活動中有標簽,則應仔細設計背壓動作。

不要指望我回答更多。 即使是大學生也能像我所給出的那樣理解 Android UI 和代碼的基本原理。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM