在 Xamarin.Forms 应用程序的 android 部分禁用 defaultFocusHighlightEnabled

Rod*_*rez 3 xamarin.android xamarin xamarin.forms

在 android 8 设备中运行的 xamarin.forms 应用程序中,我想在使用物理键盘时禁用控件突出显示(这是一种新的 android 8 行为)

android 文档说我应该为此设置 android:defaultFocusHighlightEnabled="false"

我试图在我的清单文件中添加它,但突出显示继续出现

<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:defaultFocusHighlightEnabled="false" android:versionName=
Run Code Online (Sandbox Code Playgroud)

我在哪里可以全局设置?

Rod*_*rez 5

我能够通过评论解决问题

在我的styles.xml 文件(在主要活动中引用)中,我在主题中添加了条目

主Activity.cs

[Activity(Label = "Sage Service Ops", Icon = "@drawable/icon", MainLauncher = false, Theme = "@style/MyTheme", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
Run Code Online (Sandbox Code Playgroud)

样式文件

<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
  <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
  <item name="android:defaultFocusHighlightEnabled">false</item>
</style>
Run Code Online (Sandbox Code Playgroud)


yob*_*rle 5

我通过编辑 styles.xml 解决了这个问题

<?xml version="1.0" encoding="utf-8"?>
<resources>

......

    <style name="LaunchTheme"parent="@android:style/Theme.Black.NoTitleBar">
 
        <item name="android:windowBackground">@drawable/launch_background</item>
        <item name="android:defaultFocusHighlightEnabled">false</item>
    </style>

    <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
        <item name="android:windowBackground">@android:color/white</item>
        <item name="android:defaultFocusHighlightEnabled">false</item>
    </style>

......

</resources>
Run Code Online (Sandbox Code Playgroud)

只需将以下代码添加到 styles.xml 即可修复绿色边框错误

<item name="android:defaultFocusHighlightEnabled">false</item>
Run Code Online (Sandbox Code Playgroud)

  • 对于那些不知道的人:“styles.xml”位于“/android/app/src/main/res/values/”中。 (4认同)