簡體   English   中英

將透明的操作欄分成片段

[英]Make the transparent actionbar in fragment

到目前為止,我一直在尋找如何制作透明的動作條的片段,但沒有答案。 因此,方案是,我使用導航抽屜創建一個應用程序,每個菜單都引用MainActivity相同操作欄。

但是我無法在透明模式下自定義操作欄,例如:透明操作欄:custom tabcolor 在此:

getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#330000ff")));
actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#550000ff")));

該代碼必須在setContentView之前執行,正如您所知,在片段中,我們使用onCreateView作為布局。

如何實現片段中的透明操作欄?

如果您只想制作透明的Actionbar,則可以在Fragment的onCreateView getActivity().getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#33000000")));

使用工具欄,並使用以下代碼使它的行為類似於操作欄

Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);

要將工具欄包含在布局中,請使用以下內容。

<android.support.v7.widget.Toolbar
android:id=”@+id/my_awesome_toolbar”
android:layout_height=”wrap_content”
android:layout_width=”match_parent”
android:minHeight=”?attr/actionBarSize”
android:background=”?attr/colorPrimary” />

與處理ActionBar相比,更改Toolbar的透明度非常容易

設置好之后,您可以像其他任何視圖一樣處理工具欄,即,動態更改透明度/顏色對於工具欄而言非常容易

暫無
暫無

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

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