gpt4 book ai didi

xamarin.android - 如何在Xamarin Android中将状态栏和工具栏与渐变结合在一起

转载 作者:行者123 更新时间:2023-12-02 00:55:10 25 4
gpt4 key购买 nike

I want to combine status bar and toolbar with gradient like this

我试图将状态栏设置为透明,使工具栏变大并设置渐变。
但这也使您的UI进入软导航键。

软键盘也覆盖了EditTexts。
android:windowSoftInputMode =“adjustPan”无法正常工作

if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
{
Window window = Window;
window.AddFlags(WindowManagerFlags.LayoutNoLimits);
window.AddFlags(WindowManagerFlags.TranslucentNavigation);
}

有什么方法只能使状态栏透明,而不能使底部的状态栏和导航按钮透明。

最佳答案

您也可以这样做,将代码添加到OnCreate方法中:

protected override void OnCreate(Bundle savedInstanceState)
{

if (Build.VERSION.SdkInt >= Build.VERSION_CODES.Kitkat)
{
Window w = Window;
w.AddFlags(WindowManagerFlags.TranslucentStatus);
w.SetSoftInputMode(SoftInput.StateHidden|SoftInput.AdjustResize);
}
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity_other);
}

然后在 资源/可绘制的中创建 gradient.xml :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:angle="135"
android:startColor="#f56f2c"
android:endColor="#fa9f46"/>
</shape>

最后在 layout.xml 中:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation = "vertical"
android:layout_height="match_parent"
android:fitsSystemWindows= "true"
android:background= "@drawable/gradient"
>

<!--use Toolbar-->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:title="标题"
app:titleTextColor="#fff"
app:subtitle="副标题"
app:subtitleTextColor="#fff"/>

<!--if dont use Toolbar,RePresent Toolbar-->
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="44dp">

<ImageView
android:layout_gravity="center_vertical"
android:src="@drawable/ic_arrow_back_white_24dp"
android:layout_marginLeft="10dp"
android:layout_width="35dp"
android:layout_height="35dp" />

<TextView
android:layout_gravity="center_vertical"
android:textSize="25sp"
android:gravity="center_horizontal"
android:textColor="#fff"
android:text="Test Title"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:id="@+id/scrollView1"
android:background = "#fff" //set the background color of your content
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation ="vertical" >
<!--your content -->
...
</LinearLayout>
</ScrollView>
</LinearLayout>

关于xamarin.android - 如何在Xamarin Android中将状态栏和工具栏与渐变结合在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54830783/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com