安卓开发toolbar设置logo_Android Toolbar

menu样式的定义分割线

#FF0000

2dp

修改小圆点的图标资源

@drawable/svg_more

@style/Style.Sunflower.OverFlow

ToolBar弹出菜单样式

false

10dp

0dp

@drawable/shape_pop_bg

@color/black

@dimen/sp16

使用:在需要的Activity的theme中定义

@style/Sunflower.MenuStyle

@style/Style.Sunflower.OverFlow

@dimen/dp50

@style/PopupMenuListView

效果如下所示:

2. 官网上关于ToolBar的内容

A standard toolbar for use within application content.

A Toolbar is a generalization of action bars for use within application layouts. While an action bar is traditionally part of an Activity's opaque window decor controlled by the framework, a Toolbar may be placed at any arbitrary level of nesting within a view hierarchy. An application may choose to designate a Toolbar as the action bar for an Activity using the setSupportActionBar() method.在应用程序内容中使用的标准工具栏。工具栏是在应用程序布局中使用的操作栏的概括.虽然操作栏传统上是由框架控制的活动不透明窗口装饰的一部分,但工具栏可以放置在视图层次结构中任意嵌套的级别上。应用程序可以选择使用setSupportActionBar()方法将工具栏指定为活动的操作栏。

Toolbar supports a more focused feature set than ActionBar. From start to end, a toolbar may contain a combination of the following optional elements:Toolbar支持比ActionBar更集中的功能集。工具栏从头到尾可能包含以下可选元素的组合:

1.A navigation button. This may be an Up arrow, navigation menu toggle, close, collapse, done or another glyph of the app's choosing. This button should always be used to access other navigational destinations within the container of the Toolbar and its signified content or otherwise leave the current context signified by the Toolbar. The navigation button is vertically aligned within the Toolbar's minimum height, if set.1.导航按钮 这可能是向上箭头、导航菜单切换、关闭、折叠、完成或应用程序选择的其他图形。此按钮应始终用于访问工具栏容器中的其他导航目的地及其所指示的内容,或者保留工具栏所指示的当前上下文。导航按钮在工具栏的最小高度内垂直对齐(如果已设置)。

app:navigationIcon="@drawable/icon_logo_24" setNavigationIcon(@DrawableRes int resId)

2.A branded logo image. This may extend to the height of the bar and can be arbitrarily wide.2.品牌标志形象。这可以延伸到ToolBar的高度,也可以任意宽。

3.A title and subtitle. The title should be a signpost for the Toolbar's current position in the navigation hierarchy and the content contained there. The subtitle, if present should indicate any extended information about the current content. If an app uses a logo image it should strongly consider omitting a title and subtitle.3.标题和副标题。标题应该是工具栏在导航层次结构中的当前位置及其包含的内容的路标。副标题(如果有)应指示有关当前内容的任何扩展信息。

如果一个应用程序使用一个logo图像,它应该强烈考虑省略标题和副标题。

4.One or more custom views. The application may add arbitrary child views to the Toolbar. They will appear at this position within the layout. If a child view's LayoutParams indicates a Gravity value of CENTER_HORIZONTAL the view will attempt to center within the available space remaining in the Toolbar after all other elements have been measured.4.一个或多个自定义视图。应用程序可以向工具栏添加任意子视图。它们将出现在布局中的这个位置。 如果子视图的LayoutParams表示重力值CENTER_HORIZONTAL,则在测量完所有其他元素后,视图将尝试在工具栏中剩余的可用空间内居中。

5.An action menu. The menu of actions will pin to the end of the Toolbar offering a few frequent, important or typical actions along with an optional overflow menu for additional actions.

Action buttons are vertically aligned within the Toolbar's minimum height, if set.5.动作菜单。操作菜单将固定在工具栏的末尾,提供一些常见的、重要的或典型的操作,以及附加操作的可选溢出菜单。如果设置了操作按钮,则在工具栏的最小高度内垂直对齐。

In modern Android UIs developers should lean more on a visually distinct color scheme for toolbars than on their application icon. The use of application icon plus title as a standard layout is discouraged on API 21 devices and newer.在现代Android用户界面中,开发人员应该更多地依赖于工具栏上视觉上截然不同的配色方案,而不是应用程序图标。在API 21及更高版本的设备上,不鼓励使用应用程序图标加标题作为标准布局。

ToolBar的属性

androidx.appcompat.R.attr#buttonGravity

androidx.appcompat.R.attr#collapseContentDescription

androidx.appcompat.R.attr#collapseIcon

androidx.appcompat.R.attr#contentInsetEnd

androidx.appcompat.R.attr#contentInsetLeft

androidx.appcompat.R.attr#contentInsetRight

androidx.appcompat.R.attr#contentInsetStart

androidx.appcompat.R.attr#contentInsetStartWithNavigation

androidx.appcompat.R.attr#contentInsetEndWithActions

android.R.attr#gravity

androidx.appcompat.R.attr#logo

androidx.appcompat.R.attr#logoDescription

androidx.appcompat.R.attr#maxButtonHeight

androidx.appcompat.R.attr#navigationContentDescription

androidx.appcompat.R.attr#navigationIcon

androidx.appcompat.R.attr#popupTheme

androidx.appcompat.R.attr#subtitle

androidx.appcompat.R.attr#subtitleTextAppearance

androidx.appcompat.R.attr#subtitleTextColor

androidx.appcompat.R.attr#title

androidx.appcompat.R.attr#titleMargin

androidx.appcompat.R.attr#titleMarginBottom

androidx.appcompat.R.attr#titleMarginEnd

androidx.appcompat.R.attr#titleMarginStart

androidx.appcompat.R.attr#titleMarginTop

androidx.appcompat.R.attr#titleTextAppearance

androidx.appcompat.R.attr#titleTextColor

androidx.appcompat.R.attr#menu

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在CollapsingToolbarLayout中显示工具栏的标志,图标,标题和副标题,你需要在布局文件中使用CollapsingToolbarLayout和Toolbar。 在Toolbar设置logo和标题,你可以使用以下代码: ```xml <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:logo="@drawable/logo" android:title="Title"/> ``` 要在CollapsingToolbarLayout中显示标题和副标题,你可以使用以下代码: ```xml <android.support.design.widget.CollapsingToolbarLayout android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_collapseMode="pin"/> <ImageView android:layout_width="match_parent" android:layout_height="200dp" android:src="@drawable/background_image" app:layout_collapseMode="parallax"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Title" app:layout_collapseMode="pin"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Subtitle" app:layout_collapseMode="pin"/> </android.support.design.widget.CollapsingToolbarLayout> ``` 在这个例子中,ImageView使用了parallax属性,允许图像在CollapsingToolbarLayout滚动时以不同的速度滚动。 注意:要使用CollapsingToolbarLayout和Toolbar,你需要在你的build.gradle文件中添加以下依赖项: ```gradle implementation 'com.android.support:design:28.0.0' ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值