i want to change menu icon below of toolbar. Is this possible to change the icon position.
Thanks in advance
[
You can use app:buttonGravity attribute to change the gravity of the buttons in the Toolbar and use a custom height.
Something like:
<com.google.android.material.appbar.MaterialToolbar
android:layout_height="...dp"
app:buttonGravity="center_vertical"
../>
It can work also with the androidx.appcompat.widget.Toolbar.
Related
I want my menu items on the BottomNavigationBar to have text-only labels with no icon. Unfortunately, it looks like design_bottom_navigation_item.xml always has a 24x24dp space reserved for the icon, with no publicly-exposed way to set it to gone. And even after getting past that, the label layout is set to a layout_gravity of bottom|center_horizontal, and it doesn't look like there's a way to programatically set layout_gravity to centered.
What is the fastest, easiest way to achieve the goal of a text-only menu item on the bottom nav bar? I'm thinking I can do this by creating a custom version of the item layout, then subclassing BottomNavigationItemView, BottomNavigationMenuView, and BottomNavigationView to specify that custom layout... but that seems like an awful lot of work for one little change. Am I missing something simpler?
dont put iandroid:icon property to your item
Just use the code below. I tried hard to do this easy way but failed.Then I made an alternative. Just use transparent color instead of icon drawble
<item
android:icon="#android:color/transparent"
android:id="#+id/navigation_id"
android:title="title" />
Add this in your dimens file. Then you can add padding according to your navigation view size.
<dimen name="design_bottom_navigation_height"tools:override="true">30dp</dimen>
I have a hard time finding on how to change the Toolbar title and it's drawable in every and each Activity.
There is something on Android Documentation that states that to minimize APK size. It is recommended to re-used components.
I create a separate layout, and <include layout=""/> to each of my Activities like Help, About , and etc. I also put android:label="Title" on Manifest File.
Toolbar.xml
My Main:
How do I access this included Toolbar DRAWABLE and TITLE in my Activities ?
Update: I removed ActionBar .
You are using Toolbar. So no need to do anything with ActionBar. Just set your Toolbar as supportActionBar. Then set title and icon to your Toolbar.
Use the below code:
mToolbar = (Toolbar)findViewById(R.id.Toolbar);
setSupportActionBar(mToolbar);
setTitle("About");
getSupportActionBar.setIcon(R.id.ic_arrow_back_black_24dp);
And, Remove all your mActionBar codes. Hope this helps.
well you set the support action to your custom toolbar,yet you ignore it and use mActionBar, see where i am going with this? setIcon , and setTitle should all be called relative to your custom toolbar.
I want to change Floating Action button shadow colour from black/grey to colorprimary/custom color of shadow ** shadow example like below image with **center blue FAB button with light blue shadow not grey shadow. But we can change the FAB button background color. But as you can see in image there is blue shadow of FAB button.I want to achive that thing.
try this :: app:backgroundTint="#color/colorAccentGrey"
where colorAccentGrey = YourColor
and put xmlns:app="http://schemas.android.com/apk/res-auto" at the beginning of the XML if you forggt,
and for Remove shadow :: app:elevation="0dp"
Hope this will help you.. :)
I think you have 2 options:
as #Uttam said, change the elevation of the FAB widget
to make a custom design and embed it as an image in your layout as shown here http://androidgifts.com/android-material-design-floating-action-button-tutorial/
None of the answer worked for me. So i worked this. anyhow it will give shadow like effect that enough for me
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_add_black"
app:elevation="0dp" // disable outside shawdow
app:borderWidth="30dp" // make borderwidth to 25dp or height of fab
app:backgroundTint="#00E5FF" // now you will see only this color with shawdow
android:backgroundTint="#00E5FF" // since border is 30dp u ll not see this color and if you want to check reduce border width to 25dp then ull see this color in center as a small dot.
/>
A simple solution is to remove the stroke(border-width), the default value is 0.5dp change it to 0dp, that is
app:borderWidth="0dp"
Refer Regular and mini FAB key properties in Material Design documentation!
Link - https://material.io/components/buttons-floating-action-button/android
In my application I started to set the UI to meet Material Design use the Toolbar.
I want to add the back arrow on the action bar. It looks ok but somehow, when I change my phone locality to Hebrew which is a rtl language, the arrow change it's direction and instead of pointing "out", it is now pointing "in".
Please refer to image to see how arrow looks in Hebrew and English.
Is there a way to control the arrow direction (I want it will point "out" always of course)?
I tried to add the android:layoutDirection="ltr" and android:textDirection="ltr" but it didn't helped.
Thanks for who can answer on this.
Here is the code of the Toolbar layout:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="#color/primaryColor"
app:theme="#style/MyCustomToolBarTheme"
app:popupTheme="#style/ThemeOverlay.AppCompat.Dark"
android:textDirection="ltr"
android:layoutDirection="ltr">
Finally I succeeded to change the arrow direction.
Well, actually I followed this post:
First, I have found some action bar icons and placed a drawable back icons in the project.
Then I used this code to set the arrow programmatically:
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_action_back);
The "back" icon is provided by a drawable specified in the homeAsUpIndicator attribute of the theme. You can try to override it and put your own marker (arrow out) it would be something like this:
<style name="Theme.MyTheme" parent="android:Theme.Holo">
<item name="android:homeAsUpIndicator">#drawable/out_arrow</item>
</style>
Below code adjust back arrow direction automatically (Write in your activity):
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
just set android:autoMirrored="true" in your vector drawble's xml.
If you are using Toolbar then this can be a solution:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
// getting the back arrow view
View toolbarBack = null;
for (int i = 0; i < toolbar.getChildCount(); i++)
if (toolbar.getChildAt(i) instanceof ImageButton)
toolbarBack = toolbar.getChildAt(i);
if (toolbarBack != null) {
// change arrow direction
toolbarBack.setRotationY(180);
}
I want to use an elevation in a custom layout element and I want to set in XML the value of that element using the default action bar elevation value. I can't find a way to get it in XML and I'd like to avoid to call getElevation() in code. Any tips?
Default value is 8dp, create dimen with this value and use on whole project, I got it from sources, but the material design guidelines state the action bar elevation should be 4dp.
The standard elevation of the app bar is 4dp according to material design spec. Here is the link:
https://material.io/guidelines/material-design/elevation-shadows.html#elevation-shadows-shadows
The default elevation of the action bar is 4dp. I did a little experiment by creating one custom view right below the action bar and set its elevation to 4dp. So, both were looking the same. Official documentation also mentioned 4dp standard elevation for the action bar.
Nav drawer: 16dp
App bar: 4dp
Card: 1dp to 8dp
FAB: 6dp
Button: 2dp to 8dp
Dialog: 24dp
Here App bar refers to Action bar.
Reference: Elevation
Here is the official resource available for the elevations.
The default elevation of AppBarLayout is #dimen/design_appbar_elevation (which is 4dp). Actionbar has #dimen/abc_action_bar_elevation_material as default elevation (which is 4dp as well).
These values can be found in stateListAnimator of Widget.Design.AppBarLayout and the parent of Widget.AppCompat.ActionBar respectively. The Toolbar doesn't seem to have any default elevation.