I'm trying to create an application with similar to Google Photos app UI. Support Libary Version = 25.1.0.
The problem in that with translucent status and navigation bars, widgets inside CoorinatorLayout looks not as expected. Setting fitsSystemWindows=true attribute for the BottomNavigationView makes it too large (screenshot 1) and SnakBar in that case appears behind navigation bar, not above BottomNavView or nav bar as expected. If I add fitsSystemWindows=true in Toolbar (screenshot 2) then BottomNavigationView looses it's fitsSystemWindows attribute and Toolbar content gone somewhere. It looks as a support library bug, but I'm not sure in that.
Here is my DSL code:
coordinatorLayout {
customToolbar {
id = TOOLBAR
// fitsSystemWindows = true
title = createTitle(ctx)
lparams(matchParent, dip(48))
}
frameLayout {
id = CONTENT_FRAME
backgroundResource = R.color.colorBackground
lparams(matchParent, matchParent)
}
bottomNavigationView(R.style.Base_ThemeOverlay_AppCompat_Dark) {
id = BOTTOM_NAVIGATION_VIEW
fitsSystemWindows = true
itemIconTintList = ContextCompat.getColorStateList(ctx, R.drawable.nav_item_color_state)
itemTextColor = ContextCompat.getColorStateList(ctx, R.drawable.nav_item_color_state)
backgroundResource = R.color.colorAccent
inflateMenu(R.menu.menu_drawer_2)
lparams(matchParent) {
anchorGravity = Gravity.BOTTOM
anchorId = CONTENT_FRAME
}
}
}
Related
Actually my app have 2 themes (pink and blue), handled by ResourceDictionary in App.xaml
Switching a switch in settings page change programmatically the values of the ResourceDictionary and the elements change as wanted (background, text colors etc).
It's maybe not the prettiest way but it works..
But i have a problem to change background colors of the Tabbar in android.
The color value of it is set in the Android project (colorPrimary from styles.xml and Tabbar.axml).
But i can't find
How to change or access this value from my PCL project.
Or how to change, in Android project, the value of that colorPrimary
each time the settings switch value is changed.
Or also, the best solution, make the tabbar transparent and make it
overlap the current background (if i set Color.Transparent it just
become white now)
The tabbed page code is as been created by Xamarin forms project.
public MainPage()
{
Page centerPage, rightPage, leftPage;
string TitleCenter = "S'exercer";
string TitleLeft = "Comprendre";
string TitleRight = "Aller plus loin";
switch (Device.RuntimePlatform)
{
case Device.iOS:
centerPage = new NavigationPage(new Center_Main())
{
Title = TitleCenter
};
rightPage = new NavigationPage(new Right_Main())
{
Title = TitleRight
};
leftPage = new NavigationPage(new Left_Main())
{
Title = TitleLeft
};
centerPage.Icon = "tab_feed.png";
rightPage.Icon = "tab_about.png";
leftPage.Icon = "offline_logo.png";
break;
default:
centerPage = new Center_Main()
{
Title = TitleCenter
// Nothing tab related here
};
rightPage = new Right_Main()
{
Title = TitleRight
};
leftPage = new Left_Main()
{
Title = TitleLeft
};
break;
}
Thanks
Using Xaml it is something like this:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" BarBackgroundColor="your_Color"></Tabbedpage>
Programatically:
TabbedPage page=new Tabbedpage(){ BarBackgroundColor=Color.Blue};
You can do the following in your tabbedPage constructor :
public MainPage()
{
BarBackgroundColor=Color.Blue;
}
Note: Can be used with static resources just put it in place of the color name.
Something like this
<... BarBackgroundColor={StaticResource color_name}>
Maybe if you go straight into the color that fills in the Tabbar this way:
xaml:
<ContentPage Title = "Menu" BackgroundColor = "{DynamicResource primary_colour}">
MainPage.
Application.Current.Resources ["primary_colour"] = Color.Green;
I'm using a YouTubePlayerFragment in my activity, and attempting to overlay the player with an app bar (aka action bar) when the player is in fullscreen. I'm following the guidelines and example in the YouTube Player API "Overlay ActionBar Demo" sample application and YouTubePlayerFragment documentation (more detail below).
All of this worked fine when I was extending from Activity and using the core ActionBar. But when I switch to using AppCompatActivity with the support Toolbar, a few issues arise:
The Toolbar is laid out under the status bar and navigation bar
The player no longer plays when the Toolbar is on top of it
It seems as though the player fullscreen mode used to treat the action bar as part of the system UI (along with the status bar and navigation bar), in terms of positioning and overlay, but no longer does so with the Toolbar.
Any thoughts on why this is happening or how I can use the Toolbar to properly overlay the YouTube player in fullscreen mode? I realize the Toolbar is just another view and I could probably force it to resize and reposition under the status bar, and I could set up a listener for system UI changes and show and hide my Toolbar accordingly, but I'm hoping there's a cleaner fix that I'm missing.
Here's a screenshot:
More detail: I was able to reproduce this behavior in the "Overlay ActionBar Demo" sample app (ActionBarDemoActivity), with the following changes:
Extend AppCompatActivity
Change import from android.app.ActionBar to android.support.v7.app.ActionBar
Add Toolbar to layout
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<view
class="com.examples.youtubeapidemo.ActionBarDemoActivity$ActionBarPaddedFrameLayout"
android:id="#+id/view_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
...
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="#color/material_deep_teal_500" />
</FrameLayout>
Change the theme to Theme.AppCompat.Light.NoActionBar and add windowActionBarOverlay
<style name="OverlayActionBarTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
</style>
Set the Toolbar as the action bar in onCreate()
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Note that the sample app also does the following (I didn't change these):
Implement YouTubePlayer.OnFullscreenListener
Extend the layout and set padding when not in fullscreen so that content displays below Toolbar
#Override
public void onFullscreen(boolean fullscreen) {
viewContainer.setEnablePadding(!fullscreen);
...
}
public static final class ActionBarPaddedFrameLayout extends FrameLayout {
public void setEnablePadding(boolean enable) {
paddingEnabled = enable;
requestLayout();
}
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int topPadding =
paddingEnabled && actionBar != null && actionBar.isShowing() ? actionBar.getHeight() : 0;
setPadding(0, topPadding, 0, 0);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
Set YouTube player fullscreen control flag
player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT);
Handle config changes
<activity
...
android:configChanges="keyboardHidden|orientation|screenSize"
...
</activity>
I suspect this is a bug. I filed a new bug report for the layout problem, and added a comment to an existing report about the support ActionBar/Toolbar being treated as an illegal overlay.
Toolbar overlay hidden under system UI in YouTube player fullscreen
With AppCompat theme on older devices, ActionBar is detected as an illegal overlay
In the meantime, as a workaround I'm doing the following:
Layout issue
As Troy suggested, I added android:fitsSystemWindows="true" to the Toolbar XML. This fixed the layout in fullscreen, but caused padding to be added to the Toolbar when leaving fullscreen (screenshot). I added logic to the onFullscreen(boolean) method to remove the Toolbar padding (toolbar.setPadding(0, 0, 0, 0)) but this unfortunately still shows white space in place of the padding, which disappears when the layout is next redrawn (e.g., when clicking an item, starting the player, etc). I'm still a little stumped on how to properly set the layout/padding, but the current workaround will do for now.
Illegal overlay issue
Given that showing the Toolbar will pause the YouTube player in fullscreen, I've added logic to only show the Toolbar when the player is already paused. This isn't ideal, as it forces the user to pause the player to see the Toolbar, but it's the best option I can think of.
In onFullscreen(boolean), if we enter fullscreen and the player is playing, the Toolbar is hidden.
public void onFullscreen(boolean isFullscreen) {
mFullscreen = isFullscreen;
if (isFullscreen && youTubePlayer.isPlaying()) {
toolbar.setVisibility(View.GONE);
}
else {
toolbar.setVisibility(View.VISIBLE);
}
}
When setting up the player (in onInitializationSuccess()), I added a listener to show and hide the Toolbar on play and pause:
youTubePlayer.setPlaybackEventListener(new YouTubePlayer.PlaybackEventListener() {
...
#Override
public void onPlaying() {
if (mFullscreen) {
toolbar.setVisibility(View.GONE);
}
}
#Override
public void onPaused() {
if (mFullscreen) {
toolbar.setVisibility(View.VISIBLE);
}
}
});
This code will solved your issue.
To hide navigation bar and toolbar
public void fullScreenCall() {
if(Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { //lower api
View v = getActivity().getWindow().getDecorView();
v.setSystemUiVisibility(View.GONE);
} else if(Build.VERSION.SDK_INT >= 19) {
//for new api versions.
View decorView = getActivity().getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
}
}
to back normal mode
public void normalScreenCall() {
if(Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
View v = getActivity().getWindow().getDecorView();
v.setSystemUiVisibility(View.VISIBLE);
} else if(Build.VERSION.SDK_INT >= 19) {
//for new api versions.
View decorView = getActivity().getWindow().getDecorView();
decorView.setSystemUiVisibility(0);
}
}
Try adding android:fitsSystemWindows="true" to your toolbar in your XML file.
I try to make android toolbar transition from recyclerview item name to toolbar title (text). I create it like Alex Lockwood recommendation. In appcompat-v7:22 all works fine, when I update to appcompat-v7:23 transition does't work.
Does somebody know whats happen with appcompat-v7:23?
My code (with appcompat-v7:22 all works fine):
private void startDataActivity(Activity activity, View toolbar,
Category category) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
View decor = activity.getWindow().getDecorView();
View statusBar = decor.findViewById(android.R.id.statusBarBackground);
View navBar = decor.findViewById(android.R.id.navigationBarBackground);
List<Pair> participants = new ArrayList<>(3);
participants.add(new Pair<>(toolbar, activity.getString(R.string.transition_toolbar)));
addNonNullViewToTransitionParticipants(statusBar, participants);
addNonNullViewToTransitionParticipants(navBar, participants);
ActivityOptions sceneTransitionAnimation = ActivityOptions
.makeSceneTransitionAnimation(activity,
participants.toArray(new Pair[participants.size()]));
final Bundle transitionBundle = sceneTransitionAnimation.toBundle();
activity.startActivity(ShowCategoryActivity.getStartIntent(activity,
category.getId()), transitionBundle);
} else {
activity.startActivity(ShowCategoryActivity.getStartIntent(activity,
category.getId()));
}
}
How do I change the color of the split actionbar in code, and not in xml? My user can pick the color of the actionbar, and I would like it so they could also change the color of the split action bar (the actionbar that appears at the bottom of the screen).
I'm implementing splitActionBar using android:uiOptions="splitActionBarWhenNarrow" in android manifest
so far I'm trying this, but it's not working
final int splitBarId = getResources().getIdentifier("split_action_bar", "id", "android");
final View splitActionBar = findViewById(splitBarId);
if (splitActionBar != null) {
splitActionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(actionbar_colors)));
}
}
Use this to change the split actionbar color
getActionBar().setSplitBackgroundDrawable(new ColorDrawable(Color.parseColor("#33B5E5")));
Or use this if you're using support actionbar
getSupportActionBar().setSplitBackgroundDrawable(new ColorDrawable(Color.parseColor("#33B5E5")));
Source: http://scriptedpapers.com/2014/09/25/android-implement-spilit-action-bar-change-its-background-color/
The framework doesn't provide a way to change it programmatically; however, you can use Resources.getIdentifier to find the View and adjust the background Drawable from there.
The internal id is split_action_bar.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
final int splitBarId = getResources().getIdentifier("split_action_bar", "id", "android");
final View splitActionBar = findViewById(splitBarId);
if (splitActionBar != null) {
// Adjust the background drawable
}
}
Update
Evidently there's ActionBar.setSplitBackgroundDrawable. Definitely use that callback rather than Resources.getIdentifier.
Here's a screenshot of the results:
This should work
ActionBar mActionBar = getActionBar();
mActionBar.setBackgroundDrawable(new ColorDrawable(0xff00DDED));
mActionBar.setDisplayShowTitleEnabled(false);
mActionBar.setDisplayShowTitleEnabled(true);
I can disable system clicking sound on a button if I use android:soundEffectsEnabled="false" in its layout.
I want to disable the sound effect on an Action Bar item. This attribute seems to make no difference.
How can I disable clicking sounds when user selects a menu item?
I use this:
final Toolbar toolbar = (Toolbar) this.findViewById(R.id.toolbar);
final View child = toolbar.getChildAt(2);
if (child instanceof ActionMenuView)
{
final ActionMenuView actionMenuView = ((ActionMenuView) child);
actionMenuView.getChildAt(actionMenuView.getChildCount() - 1).setSoundEffectsEnabled(false);
}
If have navigation drawer use toolbar.getChildAt(2); if not use toolbar.getChildAt(1);
Was able to get this working in Android 11 by disabling sound effects for the view (in this case, an ImageView) associated with the action bar item. Hopefully this helps someone...
View view = menuItem.getActionView();
if (view != null) {
view.setSoundEffectsEnabled(false);
}