2017-11-08 00:34:50 +00:00
|
|
|
---
|
|
|
|
id: toolbarandroid
|
|
|
|
title: ToolbarAndroid
|
|
|
|
layout: docs
|
|
|
|
category: components
|
|
|
|
permalink: docs/toolbarandroid.html
|
|
|
|
next: touchablehighlight
|
|
|
|
previous: textinput
|
|
|
|
---
|
|
|
|
React component that wraps the Android-only [`Toolbar` widget][0]. A Toolbar can display a logo,
|
|
|
|
navigation icon (e.g. hamburger menu), a title & subtitle and a list of actions. The title and
|
|
|
|
subtitle are expanded so the logo and navigation icons are displayed on the left, title and
|
|
|
|
subtitle in the middle and the actions on the right.
|
|
|
|
|
|
|
|
If the toolbar has an only child, it will be displayed between the title and actions.
|
|
|
|
|
|
|
|
Although the Toolbar supports remote images for the logo, navigation and action icons, this
|
|
|
|
should only be used in DEV mode where `require('./some_icon.png')` translates into a packager
|
|
|
|
URL. In release mode you should always use a drawable resource for these icons. Using
|
|
|
|
`require('./some_icon.png')` will do this automatically for you, so as long as you don't
|
|
|
|
explicitly use e.g. `{uri: 'http://...'}`, you will be good.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
```
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<ToolbarAndroid
|
|
|
|
logo={require('./app_logo.png')}
|
|
|
|
title="AwesomeApp"
|
|
|
|
actions={[{title: 'Settings', icon: require('./icon_settings.png'), show: 'always'}]}
|
|
|
|
onActionSelected={this.onActionSelected} />
|
|
|
|
)
|
|
|
|
},
|
|
|
|
onActionSelected: function(position) {
|
|
|
|
if (position === 0) { // index of 'Settings'
|
|
|
|
showSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
[0]: https://developer.android.com/reference/android/support/v7/widget/Toolbar.html
|
|
|
|
|
|
|
|
### Props
|
|
|
|
|
Migrate to new documentation format
Summary:
Now that the Component and API docs are no longer auto-generated, we need to consolidate on a new format for our jsdoc comments. Any help from the community will be appreciated.
In this initial pull request, we'll be tackling the following docs:
- `AccessibilityInfo`, an API doc.
- `ActivityIndicator`, a Component doc.
- `View`, a Component doc.
This top comment will serve as a style guide, and when in doubt, please refer to the individual commits in this PR.
Each commit should update a single component or API, along with any relevant markdown files.
- Documentation in the JavaScript source files should be succinct. Any verbosity should be moved over to the markdown docs in the website...
- ...by adding a link to the relevant method/prop on the website to every comment block.
- Avoid markdown style links in JavaScript source files, opt for plain old URIs.
Let code document itself:
- If a method is Flow typed, the comment block does not need to repeat this information.
- If a param can be one of several values, and the type definition is easily determined from the code, the values should not be repeated in the comment block. Again, move this to the markdown doc if not present already.
Closes https://github.com/facebook/react-native/pull/16790
Differential Revision: D6353840
Pulled By: hramos
fbshipit-source-id: 9712c459acc33092aae9909f3dd0b58a00b26afc
2017-11-17 00:44:29 +00:00
|
|
|
- [View props...](docs/view.html#props)
|
2017-11-08 00:34:50 +00:00
|
|
|
- [`overflowIcon`](docs/toolbarandroid.html#overflowicon)
|
|
|
|
- [`actions`](docs/toolbarandroid.html#actions)
|
|
|
|
- [`contentInsetStart`](docs/toolbarandroid.html#contentinsetstart)
|
|
|
|
- [`logo`](docs/toolbarandroid.html#logo)
|
|
|
|
- [`navIcon`](docs/toolbarandroid.html#navicon)
|
|
|
|
- [`onActionSelected`](docs/toolbarandroid.html#onactionselected)
|
|
|
|
- [`onIconClicked`](docs/toolbarandroid.html#oniconclicked)
|
|
|
|
- [`contentInsetEnd`](docs/toolbarandroid.html#contentinsetend)
|
|
|
|
- [`rtl`](docs/toolbarandroid.html#rtl)
|
|
|
|
- [`subtitle`](docs/toolbarandroid.html#subtitle)
|
|
|
|
- [`subtitleColor`](docs/toolbarandroid.html#subtitlecolor)
|
|
|
|
- [`testID`](docs/toolbarandroid.html#testid)
|
|
|
|
- [`title`](docs/toolbarandroid.html#title)
|
|
|
|
- [`titleColor`](docs/toolbarandroid.html#titlecolor)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
# Reference
|
|
|
|
|
|
|
|
## Props
|
|
|
|
|
|
|
|
### `overflowIcon`
|
|
|
|
|
|
|
|
Sets the overflow icon.
|
|
|
|
|
|
|
|
| Type | Required |
|
|
|
|
| - | - |
|
|
|
|
| optionalImageSource | No |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
### `actions`
|
|
|
|
|
|
|
|
Sets possible actions on the toolbar as part of the action menu. These are displayed as icons
|
|
|
|
or text on the right side of the widget. If they don't fit they are placed in an 'overflow'
|
|
|
|
menu.
|
|
|
|
|
|
|
|
This property takes an array of objects, where each object has the following keys:
|
|
|
|
|
|
|
|
* `title`: **required**, the title of this action
|
|
|
|
* `icon`: the icon for this action, e.g. `require('./some_icon.png')`
|
|
|
|
* `show`: when to show this action as an icon or hide it in the overflow menu: `always`,
|
|
|
|
`ifRoom` or `never`
|
|
|
|
* `showWithText`: boolean, whether to show text alongside the icon or not
|
|
|
|
|
|
|
|
| Type | Required |
|
|
|
|
| - | - |
|
|
|
|
| array of object: {title: string,icon: optionalImageSource,show: enum('always', 'ifRoom', 'never'),showWithText: bool} | No |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
### `contentInsetStart`
|
|
|
|
|
|
|
|
Sets the content inset for the toolbar starting edge.
|
|
|
|
|
|
|
|
The content inset affects the valid area for Toolbar content other than
|
|
|
|
the navigation button and menu. Insets define the minimum margin for
|
|
|
|
these components and can be used to effectively align Toolbar content
|
|
|
|
along well-known gridlines.
|
|
|
|
|
|
|
|
| Type | Required |
|
|
|
|
| - | - |
|
|
|
|
| number | No |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
### `logo`
|
|
|
|
|
|
|
|
Sets the toolbar logo.
|
|
|
|
|
|
|
|
| Type | Required |
|
|
|
|
| - | - |
|
|
|
|
| optionalImageSource | No |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
### `navIcon`
|
|
|
|
|
|
|
|
Sets the navigation icon.
|
|
|
|
|
|
|
|
| Type | Required |
|
|
|
|
| - | - |
|
|
|
|
| optionalImageSource | No |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
### `onActionSelected`
|
|
|
|
|
|
|
|
Callback that is called when an action is selected. The only argument that is passed to the
|
|
|
|
callback is the position of the action in the actions array.
|
|
|
|
|
|
|
|
| Type | Required |
|
|
|
|
| - | - |
|
|
|
|
| function | No |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
### `onIconClicked`
|
|
|
|
|
|
|
|
Callback called when the icon is selected.
|
|
|
|
|
|
|
|
| Type | Required |
|
|
|
|
| - | - |
|
|
|
|
| function | No |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
### `contentInsetEnd`
|
|
|
|
|
|
|
|
Sets the content inset for the toolbar ending edge.
|
|
|
|
|
|
|
|
The content inset affects the valid area for Toolbar content other than
|
|
|
|
the navigation button and menu. Insets define the minimum margin for
|
|
|
|
these components and can be used to effectively align Toolbar content
|
|
|
|
along well-known gridlines.
|
|
|
|
|
|
|
|
| Type | Required |
|
|
|
|
| - | - |
|
|
|
|
| number | No |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
### `rtl`
|
|
|
|
|
|
|
|
Used to set the toolbar direction to RTL.
|
|
|
|
In addition to this property you need to add
|
|
|
|
|
|
|
|
android:supportsRtl="true"
|
|
|
|
|
|
|
|
to your application AndroidManifest.xml and then call
|
|
|
|
`setLayoutDirection(LayoutDirection.RTL)` in your MainActivity
|
|
|
|
`onCreate` method.
|
|
|
|
|
|
|
|
| Type | Required |
|
|
|
|
| - | - |
|
|
|
|
| bool | No |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
### `subtitle`
|
|
|
|
|
|
|
|
Sets the toolbar subtitle.
|
|
|
|
|
|
|
|
| Type | Required |
|
|
|
|
| - | - |
|
|
|
|
| string | No |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
### `subtitleColor`
|
|
|
|
|
|
|
|
Sets the toolbar subtitle color.
|
|
|
|
|
|
|
|
| Type | Required |
|
|
|
|
| - | - |
|
|
|
|
| [color](docs/colors.html) | No |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
### `testID`
|
|
|
|
|
|
|
|
Used to locate this view in end-to-end tests.
|
|
|
|
|
|
|
|
| Type | Required |
|
|
|
|
| - | - |
|
|
|
|
| string | No |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
### `title`
|
|
|
|
|
|
|
|
Sets the toolbar title.
|
|
|
|
|
|
|
|
| Type | Required |
|
|
|
|
| - | - |
|
|
|
|
| string | No |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
### `titleColor`
|
|
|
|
|
|
|
|
Sets the toolbar title color.
|
|
|
|
|
|
|
|
| Type | Required |
|
|
|
|
| - | - |
|
|
|
|
| [color](docs/colors.html) | No |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|