android-layout - 如何删除工具栏中的剩余空间(以及上方和下方)
问题描述
如何删除<NavigationPage.TitleView>
Xamarin.Forms 周围的丑陋蓝色空间?
<NavigationPage.TitleView>
<StackLayout Orientation="Horizontal" Margin="0" Spacing="0" Style="{StaticResource BkGroundToolbarStyle}">
...
</StackLayout>
</NavigationPage.TitleView>
我已经测试了这篇文章:Wendy Zang - MSFT,但正如你所见,它对我不起作用。这是Toolbar.xml
我的Android项目中文件的内容:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:contentInsetLeft="0dp"
android:contentInsetRight="0dp"
android:contentInsetStart="0dp"
android:contentInsetEnd="0dp"
android:contentInsetStartWithNavigation="0dp"
android:paddingLeft="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetRight="0dp"
app:contentInsetEnd="0dp"
/>
我也尝试了这个解决方案:Mauro Cavallin - Lemcube但我得到一个错误:'V7' doesn't exist in the namespace 'Android.Support' in this line:
var toolbar = this.FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
你如何成功?或者你为什么没有同样的问题?
编辑:感谢 Cherry Bu - MSFT 解决方案,我可以删除左边的空间。但是上面和下面的两条线仍然存在。
这可能是由于Xamarin 中的 BAD Height 计算导致的吗?这是我的工具栏的定义:
<NavigationPage.TitleView>
<StackLayout Style="{DynamicResource ToolbarBkGrndColorStyle}"
Orientation="Horizontal" Margin="0" Spacing="0" Padding="0"
HorizontalOptions="Fill" VerticalOptions="Fill">
...
</StackLayout>
</NavigationPage.TitleView>
如果我用这个替换stacklayout的定义,问题就会消失(但我的内容不再可见......):
<StackLayout Style="{DynamicResource ToolbarBkGrndColorStyle}"
Orientation="Horizontal" Margin="0" Spacing="0" Padding="0"
HorizontalOptions="FillAndExpand" HeightRequest="1000">
那么,我应该如何定义这个 Stacklayout 的高度???
解决方案
你可以尝试使用androidx.appcompat.widget.Toolbar
来替换android.support.v7.widget.Toolbar
。
<androidx.appcompat.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
/>
并将 image 或 stacklayout HeightRequest 设置为足够。
<NavigationPage.TitleView>
<StackLayout
Margin="0"
BackgroundColor="Gray"
HorizontalOptions="FillAndExpand"
Orientation="Horizontal"
Spacing="0"
VerticalOptions="FillAndExpand">
<Label Text="Hello World" />
<Image HeightRequest="80" Source="check.png" />
</StackLayout></NavigationPage.TitleView>
推荐阅读
- logging - .NetCore 数据库 ILoggerProvider 存储库上下文 null
- visual-c++ - 从 Linux 到 Windows 的 C++
- javascript - Vue & Vuex - 不排序
- r - soffice 仅在从 RStudio 调用时失败
- flask - WSGI 容器是否与 AWS Lambda 相关?
- scheme - 计算机如何读取程序
- bash - 两个字符串之间的bash比较运算符问题
- scala - Databricks 中从 csv 格式到 Redis 哈希格式的数据传输
- java - Vert.x 3.9.4 上的 Redis 连接丢失
- python - 预期的字符串迭代不会迭代