- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要大量帮助来解决 MasterDetail
的问题Xamarin.Forms 中的页面。
我想做的是,非常简单地自定义 NavigationBar
的背景使用渐变。我的设置是一个带有 Prism 的 Xamarin.Forms 应用程序,我首先在其中登录用户,然后导航到 MasterDetail
像这样的页面:
await NavigationService.NavigateAsync("MyMasterDetailPage/NavigationPage/MyDetailPage")
我遇到的问题是无论我做什么我都无法改变 NavigationBar
的颜色.
我尝试了几种不同的 CustomRenderers
变体(当前适用于 Android),以及仅添加自定义 TitleView
到 Detail
PCL 项目中的页面。我也试过更改 styles.xml 文件,更改 ToolBar.axml 以使用我制作的可绘制对象,但到目前为止我仍然没有运气.
任何帮助将不胜感激,因为我已经为这个问题苦苦挣扎了几天。
下面是正在发生的事情的屏幕截图:
工具栏.axml:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:background="@drawable/gradient_background_drawable"
/>
样式.xml:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="MainTheme" parent="MainTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
<item name="windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="windowActionBar">false</item>
<!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette -->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#89D362</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#89D362</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">#FF4081</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight and colorSwitchThumbNormal. -->
<!--<item name="windowActionModeOverlay">true</item>-->
<item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>
<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#FF4081</item>
</style>
<style name="DrawerArrowStyle" parent="@style/Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#89D362</item>
</style>
</resources>
gradient_background_drawable:
<?xml version="1.0" encoding="utf-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:type="linear"
android:angle="270"
android:startColor="#000E0E"
android:endColor="#3D3939">
</gradient>
</shape>
MasterDetailPageRenderer:
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
base.OnLayout(changed, l, t, r, b);
var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
if (toolbar != null)
{
for (int i = 0; i < toolbar.ChildCount; i++)
{
var child = toolbar.GetChildAt(i);
child.Background = Context.GetDrawable(Resource.Drawable.gradient_background_drawable);
}
toolbar.Background = Context.GetDrawable(Resource.Drawable.gradient_background_drawable);
}
}
导航页面渲染器:
protected override void OnElementChanged(ElementChangedEventArgs<NavigationPage> e)
{
base.OnElementChanged(e);
if (e.OldElement != null || Element == null)
{
return;
}
var actionBar = ((FormsAppCompatActivity)Context).SupportActionBar;
actionBar.SetBackgroundDrawable(Context.GetDrawable(Resource.Drawable.gradient_background_drawable));
}
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
base.OnLayout(changed, l, t, r, b);
var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
if (toolbar != null)
{
//for (int i = 0; i < toolbar.ChildCount; i++)
//{
// var child = toolbar.GetChildAt(i);
// child.Background = Context.GetDrawable(Resource.Drawable.gradient_background_drawable);
//}
toolbar.Background = Context.GetDrawable(Resource.Drawable.gradient_background_drawable);
}
}
public override void OnViewAdded(Android.Views.View child)
{
base.OnViewAdded(child);
if (child.GetType() == typeof(Android.Support.V7.Widget.Toolbar))
{
_toolbar = (Android.Support.V7.Widget.Toolbar)child;
_toolbar.Background = Context.GetDrawable(Resource.Drawable.gradient_background_drawable);
}
}
最佳答案
我通过使用模板 Master-Detail Page
创建一个新应用来实现该功能。方法就是按照你说的设置Toolbar.axml
的background
。
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:background="@drawable/gradient_background_drawable"
/>
为了让效果更明显,我改变了渐变色。您可以改回自己的渐变颜色。
文件 gradient_background_drawable.xml
<?xml version="1.0" encoding="utf-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:type="linear"
android:angle="270"
android:startColor="#008B00"
android:endColor="#9AFF9A">
</gradient>
</shape>
此外,记得在文件App.xaml
中删除与工具栏相关的Background
属性。
文件 App.xaml
<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="FormApp202011.App">
<Application.Resources>
<ResourceDictionary>
<!--Global Styles -->
<Color x:Key="NavigationPrimary">#2196F3</Color>
<Style TargetType="NavigationPage">
<Setter Property="BarTextColor" Value="Red" />
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
结果:
关于android - Xamarin.Forms MasterDetail 页面 NavBar 自定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59545362/
我仍在学习网页设计的诀窍,并且我无法理解一些事情是如何工作的...... 我创建了一个函数来切换导航栏标题背景颜色,我发现以下内容是正确的,但不确定原因: 作品: $(".navbar.navbar-
在 Twitter bootstrap 2.3.2 中,我可以有类似的东西: http://jsfiddle.net/aQwUZ/3/
我是 bootstrap、jquery 和 javascript 的新手,我在一个网站上工作,但我遇到了一个问题。 . .我需要顶部的导航栏在超小屏幕上以折叠状态加载。现在,该栏在 XS 屏幕上是垂直
我正在学习使用 Ruby on Rails 编写代码,并且正在制作一个随机网页。我添加了 Bootstrap 导航栏。 我正在尝试将导航栏的边框更改为无,而不是: .navbar { bord
每当我学习 ionic 的教程时,我都会看到短语 *navbar。这是什么意思?我知道 * 表示它在模板中插入标签,但无法真正理解这个表达式.. 最佳答
我不知道如何正确表达这一点,但我想做的是让顶部栏( http://puu.sh/iNdBj/7f11027db0.png )在向下滚动时折叠并在回到顶部时重新出现,我想让底部栏填充顶栏的位置。 目前的
这是我第一次使用 bootstrap,我使用 roots 主题作为准系统模板。我在 header-top-navbar.php 的 navbar-header 元素中放置了一个图像我还将它放在一个 d
在我网站的顶部,主要的导航类是: navbar navbar-default navbar-fixed-top bg 我正在努力做到这一点,当你滚动时,类会更改为这样我就可以创建一个更优雅、更简单的滚
这是我的问题: collapse problem 如您所见,我的 navbar-collapse div 进入了导航栏区域。你能帮我解决一下吗? Title
我已经为类尝试了很多不同的选项来更改 navbar 上的文本颜色,特别是 navbar-brand 元素。我的 .navbar-brand color:purple; CSS 类没有运行。你能帮我弄清
我正在尝试使用 nav navbar-nav navbar-right 创建一个下拉菜单。我让它在移动设备(较小的屏幕)上对齐但是当我点击下拉菜单时它不会将菜单项向下推但是而是下拉其他菜单项。我不确定
我的导航栏没有改变颜色。 Navbar.jsx 文件中的 Navbar.css 文件的路径是否正确? import React, { Component } from 'react'; import
我无法让我的 navbar-header 和 navbar-nav 元素正确排列。 navbar-header 在 navbar 中垂直居中,而 navbar-nav 看起来像是 align="top
当我的屏幕宽度达到 767px 时,导航会异常折叠。当我转到 768px 时,navbar-nav 会低于 navbar-brand。直到我达到 795px,navbar-brand 和 navbar
我正在尝试实现一个固定的导航栏,但是在一定的屏幕尺寸(〜宽度:989)之后,导航栏向下移动。它也不适用于移动设备。 图片: 导航栏完全贴在页脚上,而不是停留在页面顶部。 您可以在以下位置查看代码:ht
我正在尝试右对齐我的 NavBar,但每当我添加 float:right 时,导航栏都会向右移动,但似乎已禁用。 参见此处:goo.gl/46yUrt 代码: /** * 4.2 Navigatio
我正在使用 Bootstrap 4,我希望我的 navbar-toggler 出现在 navbar-brand 之前,例如 this ,但是如果我将 navbar-toggler 放在第一位,我的对齐
如何使 navbar-header 全宽或单独成一行? 我在 collapse navbar-collapse 上添加了 clear:both; 但所有的填充都弄乱了。
.navbar 和 .navbar a 有什么区别 .navbar { overflow: hidden; background-color: #333;
在 Twitter bootstrap 的 starter-template.html 中,navbar 写成 ... 但是,如果我将标记更改为
我是一名优秀的程序员,十分优秀!