Fitting View into Actionbar - android

I'm working on integrating a custom view into the action bar. Currently I am successfully getting the view to display. However some of the view is appearing off the edge of the action bar boundary.
Is there any way I can set the action bar to adjust it's size to fit the entire contents of the view or is the only solution to make the various components of the view slightly smaller...
many thanks

You could adjust the height of the ActionBar from the action bar theme style, or you define your custom theme which inherits from the parent theme, and add the "height" attribute. (I don't remember how it was called exactly)

Related

How to implement system bars insets with edge-to-edge gesture navigation?

I'm trying to add the edge-to-edge stuff for the gesture navigation bar to the Tip Time app from Google. I added the transparent navigationBarColor XML tag to themes.xml as well as the following code to the onCreate() function of MainActivity.kt:
This was directly copy-pasted from the documentation. Android Studio says that "it cannot find a parameter with this name" for each of the three margins. I noticed that changing the parenthesis right after <ViewGroup.MarginLayoutParams> to curly braces fixes the compiler error. Maybe the documentation is just wrong?
Anyways, even after fixing that, the app still doesn't look right:
As you can see, the entire view gets shifted up slightly and the "Cost of Service" TextView is partially cut-off by the app bar. What would I need to change to implement the system/navigation bar insets for edge-to-edge content so the UI looks nice? Also, as a side-question, how can I change the dark blue color of the system status bar to match the color of the app bar so that they look blended?
As per documentation for edge to edge contents:
Draw behind the status bar if it makes sense for your content and
layout, such as in the case of full-width imagery. To do this, use
APIs such as AppBarLayout, which defines an app bar pinned to the top
of the screen.
So, while handing the window insets (especially the top one), you can't use the default ActionBar, instead you need to customize that with AppBarLayout and ToolBar, and to make it act as the ActionBar, use setSupportActionBar(), and a NoActionBar app theme; it'd be <style name="Theme.TipTime" parent="Theme.MaterialComponents.DayNight.NoActionBar"> in the shared repo.
the entire view gets shifted up slightly and the "Cost of Service" text field is partially cut-off by the app bar.
The reason that the sample uses the default ActionBar instead of a customized one; when it comes to handle the top window insets, it won't affect the default ActionBar; notice that you pass in the activity's root layout to setOnApplyWindowInsetsListener callback, and as the ActionBar is not a part of the activity, it won't be affected. Therefore the activity is shifted up behind the ActionBar when the top inset is removed. So, to solve this you have either to totally remove the default ActionBar or to use a custom toolbar instead.
Also, as a side-question, how can I change the dark blue color of the system status bar to match the color of the app bar so that they look blended?
Use a transparent status bar color in the app's theme:
<item name="android:statusBarColor" tools:targetApi="l">#android:color/transparent</item>

Adding tool bar as an Action bar creating additional margin

I'm trying to build a layout which is using CollapsingToolbarLayout to perform collapse of Toolbar and allow Recycle View contain to scroll.
It work great except.
View that I want to hookup on scrolling, and scroll till action bar height.
What I need:
Scroll Sticky Header with/till it's own size, not action bar size.
Small Snippet from XML i'm using added here.
What is my observation:
There must be some dependency between CollapsingToolbarLayout and toolbar I'm using as an Action Bar.
If use theme with Default Action bar, then everything worked so perfect.
Any suggestion if I'm missing anything!!

Is possible have to different menu in Action Bar? (Kotlin)

I have an app, which have an action menu item on the right (2).
I need an ulterior menu in the left(1) or a button in the action bar, is that possible?
I attach a image.
enter image description here
You may create a custom toolbar. The standard height of a toolbar is 89dp.
To create a custom toolbar you should make your activity view container RelativeLayout. Then create a custom toolbar view (it may also be RelativeLayout) which height is 89dp. Then add your toolbar to the main container and set alignParentTop to true. So you have a custom flexible toolbar and you can add any view to it.
This way is very comfortable to use any custom views on your toolbar.
I also faced the same situation of customizing action bar. After a lot of searching I got the solution which is Toolbar.
Checkout: https://developer.android.com/training/appbar/setting-up
I think from now on, you should start using Toolbar as the default action bar for your apps. It provides high level of customization and material design features.

How can I do to customize the actionbar?

Hi guys I wanna ask you if it is possible to completely redesign the actionbar. I have no buttons on my bar and I want to place a "png" file instead of the default bar..is it possible? Thank you so much :)
It is possible not to use any ActionBar at all.
Just place any control which has a drawable background settable (I normally use a TextView) on the top of your Activity and set its background image.
A TextView may also contain a title and one or more "icons" (compound drawables).
And it's also clickable, if needed.
If you design your layout properly; a RelativeLayout container (I prefer this kind of container) may help: set the TextView as alignParentTop="true" and the map as layout_below="#id/yourTextView_ID" and layout_height="match_parent" (to fill the remaining space).
Let the RelativeLayout be the overall (root) container, so that it contains everything.
As such, its children can be positioned relatively.
To let the map be positioned under the "title", Just skip the layout_below attribute to the map. And add alignParentTop="true" to it.
If you don't use action bar functionality like Up navigation or drawer navigation toogle from action bar.You can use at window like this and style your title in your theme:
getWindow.requestFeature(FEATURE_CUSTOM_TITLE);
And at style file like this:
<item name="android:windowTitleSize">#dimen/title_height</item>
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground</item>
<item name="android:windowTitleStyle">#style/CustomWindowTitle</item>
If you want to use action bar functionality, override action bar custom view by this:
getActionBar().setCustomView(R.layout.custom_actionbar);

Android layouts: fit View under Action Bar

I'm using the action bar as a translucent overlay (like the Google Earth app), using:
<item name="android:windowActionBarOverlay">true</item>
All my Views of full-screen height now extend beneath the action bar, but I only want one of them to do that. So my question is, is there a way to automatically fit Views so that they do not extend underneath the action bar overlay? I'd rather not have to use a custom dp setting.
There is no way to fit the views automatically since action bar is in overlay mode. You need to set action bar height as marginTop for the view. You can refer the android documentation here

Categories

Resources