How to set expandedTitleMarginBottom for CollapsingToolbarLayout programmatically - android

We have some hidden views inside CollapsingToolbarLayout. So when we are making those view visible alignment of title is changed. so we need to change the value of expandedTitleMarginBottom for adjusting alignment.
How can we set expandedTitleMarginBottom for CollapsingToolbarLayout programmatically ?

For anyone searching for this : you can call setExpandedTitleMarginBottom(int px) on the collapsibleToolbarLayout

Related

Change the opacity/transparency of a view and affect the child views too

I have a relative layout with child TextViews.
The background of the parent RelativeLayout is white and I was wondering how I could change the alpha to change the opacity of the whole view programmatically (including children).
I am trying:
getBackground().setAlpha(0.4);
But that expects an int and not a float.
If I do:
getBackground().setAlpha((int)(0.4 * 255));
The latter changes the view but makes it darker than I want. Also the children do not seem to change. It seems to affect only the background while I want something that makes everything more "grayed" out/less transparent.
What am I doing wrong?
Have you tried using android:background="#88000000" in layout file. You can change alpha and color values as required.
That's because you are changing the backgound of the layout and not the layout itself. So instead of myRelativeLayout.getBackground().setAlpha(), use this: myRelativeLayout.setAlpha(0.4f).

Pin collapsingtoolbar child

app:layout_collapseMode="pin"
This attribute seems to only work if the view is a toolbar and won't work on other views such as relativelayout, why?
app:layout_collapseMode= "pin"
pin is set to this mode, the Toolbar can remain on the screen when the CollapsingToolbarLayout is fully shrunk.
Fixed mode, finally fixed at the top of the fold
Because it was CollapsingToolbarLayout's attribute .
And it also used in CoordinatorLayout .

Collapsing toolbar anchored view is hidding when collapse

I need to display a TextView (The circular shape with "0") anchored to the toolbar, like a FAB, but it must be ALWAYS VISIBLE.
My problem is that when I collapse the toolbar (scrolling the recyclerView), at the fully collapsed state, it hides the half of the view...
The TextView layout has this properties:
app:layout_anchor="#id/appbar"
app:layout_anchorGravity="bottom|center_horizontal"
Anyone knows how to solve it?
If you want your TextView be over the toolbar, in this case, you can try to set higher elevation value to TextView. In some cases, it worked for me.
For example:
android:elevation="15dp"

How to set custom layout into material toolbar?

I'm trying to make toolbar like in this app:
play.google.com/store/apps/details?id=com.pickup.pickrup
But I can't set custom layout into toolbar.
After adding custom layout appears some margins below and above.
Help me please!
The Toolbar is just a ViewGroup, so if you have your layout or custom view you can just add it to the Toolbar using the ViewGroup#addView(View view) method. For example, if you instantiated your view and called it myView, you can do: myToolbar.addView(myView)
I have solved this problem specifying instead layout height android:layout_height="wrap_content"
this - landroid:layout_height="?actionBarSize", which is 56dp.
So margins from top and bottom have dissapeared.

Android: ListView xml layout not showing background image when scrolled

I have an Activity with a ListView, I set the background image to the view programatically.
When I scroll down my list, the background image turns to white ( because my theme is Theme.Light.NoTitleBar).
How can I make it scroll with the blue background intact?
If the above point works, how can I change the text color of ListView to white instead of black?
Normal ListView
Scrolling ListView
Pressing ListView item
Use the attribute android:cacheColorHint="#000000" in ListView Tag
Regarding make TextView's color black or white, you can refer here to make a custom TextView for your ListView row, The extra work you have to do is just add another attribut inside TextView tag like this
android:textColor="#FFF" //or #FFFFFF for white
add a attribute on the ListView Tag
android:cacheColorHint="#00000000"// setting as a transparent color
This is due because of an optimization. To remove this, just set the cacheColorHint of your listView to transparent, like this: android:cacheColorHint="#00000000"
Full post here: http://android-developers.blogspot.fr/2009/01/why-is-my-list-black-android.html
You can Wrap that ListView inside on LinearLayout having same background and then remove ListView's Background that should work fine. :)
Please check this answer. I have got the same issue and it is fixed by putting view = null in adapter side.

Categories

Resources