use*_*452 3 search xaml searchbar xamarin.forms
我想隐藏 Xamarin Forms 搜索栏中的搜索图标。这是我需要的用户界面。
这是我正在使用的自定义渲染器
[assembly: ExportRenderer(typeof(searchTab), typeof(StyledSearchBarRenderer))]
namespace RestaurantApp.Droid.Renderers
{
class StyledSearchBarRenderer : SearchBarRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
{
base.OnElementChanged(e);
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);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的 XAML 代码
<Frame Padding="0" OutlineColor="DarkGray" HasShadow="True" HorizontalOptions="FillAndExpand" VerticalOptions="Center">
<local:searchTab x:Name="searchBar" Placeholder="Please search for a vendor or product name" PlaceholderColor="Black" TextColor="Black" HorizontalOptions="FillAndExpand" VerticalOptions="Center" />
</Frame>
Run Code Online (Sandbox Code Playgroud)
这是我必须隐藏的
我没有得到任何示例或任何代码来在 Xamarin Forms 中完成此操作。有什么建议?
在我的 Android Renderer 中,我将如何做到这一点:
var searchView = base.Control as SearchView;
int searchIconId = Context.Resources.GetIdentifier("android:id/search_mag_icon", null, null);
ImageView searchViewIcon = (ImageView)searchView.FindViewById<ImageView>(searchIconId);
searchViewIcon.setImageDrawable(null);
Run Code Online (Sandbox Code Playgroud)
这应该清除搜索图标
如有疑问,请随时回复。
归档时间: |
|
查看次数: |
1937 次 |
最近记录: |