是否有簡單的方法添加工具欄下的視圖,而不會影響其當前的外觀?我只是想在工具欄文本的正下方添加一個額外的視圖。請注意,工具欄有陰影,只是在工具欄小部件下方添加視圖將無法達到我想要的效果。如何在工具欄下方添加視圖?
回答
使用此代碼來做到這一點。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:orientation="vertical">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/app_color"
android:titleTextAppearance="@android:color/white"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- **** Place Your Content Here **** -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="My Content"/>
<!-- **** This is your view that appears below toolbar **** -->
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="@drawable/toolbar_dropshadow" />
</FrameLayout></LinearLayout>
@toolbar_dropshadow
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="@android:color/transparent"
android:endColor="#88333333"
android:angle="90"/>
</shape>
欲瞭解更多信息,請點擊此鏈接:https://stackoverflow.com/a/26904102/3907780
<android.support.v7.widget.Toolbar
mlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/custom_tool_bar"
android:layout_width="fill_parent"
android:layout_height="@dimen/actionbar_height"
android:gravity="center">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
//Add your components here
</RelativeLayout>
</android.support.v7.widget.Toolbar>
嘗試過它,它仍然出現在標題和菜單按鈕之間 –
張貼您的xml和屏幕截圖 – Prachi
黑色區域[截圖](http://i.imgur.com/qwXmup5.jpg)是我添加的視圖 –
什麼在上述職位的工作對我來說是改變佈局的工具欄是成線性佈局。
在使用框架佈局時,視圖位於工具欄下方。
如果您使用的是RelativeLayout的,使用方法:
<android.support.v7.widget.Toolbar
mlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/custom_tool_bar"
android:layout_width="fill_parent"
android:layout_height="@dimen/actionbar_height"
android:gravity="center">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
//Add your components here, ie.:
<MyView android:id="@+id/black_box"
android:layout_below="@id/my_toolbar" //relativity left or right available too
android:layout_width="match_parent"
etc.etc./>
</RelativeLayout>
</android.support.v7.widget.Toolbar>`
我不知道爲什麼你的工具欄高於佈局範圍,但嘗試,讓我們知道。
在Toolbar
像添加android:layout_height="?attr/actionBarSize"
:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:titleTextColor="#ffffff"
android:background="#ECA539"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
,然後在Relativelayout
添加android:layout_marginTop="?attr/actionBarSize"
象下面這樣:
<RelativeLayout
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:layout_height="wrap_content">
- 1. 如何在工具欄下添加工具欄 - android
- 2. 在android工具欄中添加視圖
- 3. 將工具欄添加到視圖
- 4. 如何添加工具欄
- 5. 如何正確添加自定義視圖到工具欄?
- 6. 如何以編程方式在工具欄面板中添加工具欄?
- 7. 如何添加自定義圖標stimulsoft工具,工具欄
- 8. 添加工具欄下面意見CoordinatorLayout
- 9. 如何在工具欄中的按鈕下添加標籤?
- 10. 在UITableView上方添加工具欄以便在UISplitViewController詳細視圖中使用
- 11. 如何更改Android工具欄視圖?
- 12. jqGrid:如何添加水平工具欄
- 13. 如何將CheckBox添加到工具欄?
- 14. 如何將textField添加到工具欄
- 15. 如何在Drupal 8工具欄中添加公司圖標
- 16. 如何在工具欄內添加Logo圖像
- 17. 如何在自定義工具欄上添加圖標?
- 18. 添加圖像到工具欄
- 19. 如何將工具欄添加到視口?
- 20. 如何將我的工具欄移動到下一個視圖
- 21. 如何將上下文菜單項添加到工具欄?
- 22. 添加工具欄JSQMessagesViewController
- 23. 自動添加工具欄
- 24. 添加三個子視圖後工具欄消失
- 25. 將工具欄添加到拾取器視圖
- 26. 無法將按鈕添加到表格視圖工具欄
- 27. 如何以編程方式將工具欄添加到LinearLayout
- 28. 如何將工具欄添加到iphone應用程序中的表格視圖?
- 29. 如何在視圖下添加布局
- 30. 如何向操作添加/更改Android Studio工具欄圖標?
發表您的xml文件 – Prachi
@Prachi我沒有任何(還) ..我只使用默認的工具欄,只是想知道如何在其標題的文本視圖下添加視圖 –
與將組件添加到「相對佈局」或「線性佈局」相同的方式 – Prachi