gpt4 book ai didi

xamarin.ios - Xamarin Forms 中的搜索栏样式更改

转载 作者:行者123 更新时间:2023-12-02 03:45:35 26 4
gpt4 key购买 nike

我需要在 Xamarin Android 和 Xamarin iOS 的应用程序中使用搜索栏。

我必须在我的应用程序中实现以下搜索栏。

enter image description here enter image description here

请查找 xaml 中使用的代码,

<Frame Padding="0" OutlineColor="DarkGray" HasShadow="True" HorizontalOptions="FillAndExpand"  VerticalOptions="Center">
<SearchBar x:Name="searchBar" Placeholder="Search" PlaceholderColor="LightGray" TextColor="#000000" HorizontalOptions="FillAndExpand" VerticalOptions="Center" TextChanged="SearchBar_TextChanged"/>
</Frame>

我的搜索栏如下所示,需要从 xamarin android 中删除突出显示的行。 enter image description here还可以找到搜索栏渲染器代码,

protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
{
base.OnElementChanged(e);
var color = global::Xamarin.Forms.Color.LightGray;
var searchView = (Control as SearchView);
var searchIconId = searchView.Resources.GetIdentifier("android:id/search_mag_icon", null, null);
if (searchIconId > 0)
{
var searchPlateIcon = searchView.FindViewById(searchIconId);
(searchPlateIcon as ImageView).SetColorFilter(color.ToAndroid(), PorterDuff.Mode.SrcIn);
}
var symbolView = (Control as SearchView);
var symbolIconId = symbolView.Resources.GetIdentifier("android:id/search_close_btn", null, null);
if(symbolIconId>0)
{
var symbolPlateIcon = symbolView.FindViewById(symbolIconId);
(symbolPlateIcon as ImageView).SetColorFilter(color.ToAndroid(), PorterDuff.Mode.SrcIn);
}
}

Xamarin Android:我使用框架控件在搜索栏中显示边框。我必须删除搜索栏边框底线或其中的边框颜色。

Xamarin iOS:我必须实现搜索栏控制,如图所示。我必须在搜索时删除搜索栏中显示的取消字。还需要删除其中的半径。

有人对此提出建议吗?

最佳答案

在 Android 中,您可以通过 id 找到 search_plate 并将其设置为 Transparent,如下所示:

if (Control != null)
{
var color = global::Xamarin.Forms.Color.LightGray;
var searchView = Control as SearchView;

int searchPlateId = searchView.Context.Resources.GetIdentifier("android:id/search_plate", null, null);
Android.Views.View searchPlateView = searchView.FindViewById(searchPlateId);
searchPlateView.SetBackgroundColor(Android.Graphics.Color.Transparent);
}

在iOS中,你可以找到UISearchBar的Textfield,然后自定义它的边框样式。并通过将 ShowsCancelButton 设置为 false 来删除“取消”按钮。例如,像这样:

protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (Control != null)
{
Control.ShowsCancelButton = false;

UITextField txSearchField = (UITextField)Control.ValueForKey(new Foundation.NSString("searchField"));
txSearchField.BackgroundColor = UIColor.White;
txSearchField.BorderStyle = UITextBorderStyle.None;
txSearchField.Layer.BorderWidth = 1.0f;
txSearchField.Layer.CornerRadius = 2.0f;
txSearchField.Layer.BorderColor = UIColor.LightGray.CGColor;

}
}

关于xamarin.ios - Xamarin Forms 中的搜索栏样式更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46894420/

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