0
我正在使用新的android工具欄。如何更改Android工具欄視圖?
/* Jump into, after the user clicks on a listview item */
private void toogleToolbar() {
if (isStandardToolbar)
customToolbar();
else
originalToolbar();
isStandardToolbar = !isStandardToolbar;
}
/* Called inside onCreate and if nothing was clicked */
private void originalToolbar() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
}
/* Called after an click event */
private void customToolbar() {
LayoutInflater inflater = this.getLayoutInflater();
Toolbar toolbar = (ToolBar) inflater.inflate(R.layout.newtoolbar, null);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
}
它工作到目前爲止,但現在我想要更改工具欄視圖,點擊列表元素後。 這是我的問題,因爲最後一段代碼不會產生異常或其他問題,所以應該都可以。但我只看到「舊」工具欄。我試圖將可見性設置爲GONE或INVISIBLE到舊的,但它沒有任何影響。
在我的activity_main.xml中,我包含了R.id.toolbar,但我認爲第二個代碼必須覆蓋舊的!
編輯: AFAIK,新的工具欄應該替換舊的actionBar。工具欄用於放置導航或其他特定內容。我的情況是,我想創建一個小的操作菜單,用戶可以在其中編輯或刪除列表項。
其他添加一些代碼。無論如何,我認爲你沒有正確使用對工具欄的調用。事實上,我敢打賭。嘗試插入整個工具欄,並使用object.visibility(View.GONE)和View.VISIBLE進行播放。 – Maga
我認爲工具欄應該是活動佈局的一部分。在其他情況下,它不會出現。您是否想根據某些條件對工具欄進行特定的佈局? – Abdullah
是的,我想在某些條件下進行其他佈局。我做了我的第一篇文章。 – user3417078