3

I am creating an android application in xamarin. I am using a web view to display a website. To enter the input in the text box i have created custom keyboards, So i have to keep my app in full screen. I have manged to do that and My app is working properly.

But problem occurs when user connects the external keyboard( by OTG cable).

1. My Activity is restarting when i attach or detach the external keyboard.

I have tried the following code to prevent the activity restart

(a) I have written the following code in AndroidManifest.xml

<application android:configChanges="orientation|keyboard|keyboardHidden|screenSize" android:label="ABC" android:icon="@drawable/AppIcon"></application>

(b) I have added the attribute to the activity

[Activity (Label = "ABC",Icon = "@drawable/AppIcon", ConfigurationChanges = ConfigChanges.Keyboard|ConfigChanges.KeyboardHidden|ConfigChanges.ScreenSize,ScreenOrientation = ScreenOrientation.Landscape)]          
public class HomeActivity : Activity
{}

2. Navigation bar with keyboard switching key is showing up when i type something from external keyboard

For this i have written the following code.

public static SystemUiFlags flags = (SystemUiFlags.Visible | SystemUiFlags.LayoutHideNavigation | SystemUiFlags.LayoutFullscreen | SystemUiFlags.HideNavigation |
       SystemUiFlags.Fullscreen | SystemUiFlags.ImmersiveSticky);
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        //hide action bar and title bar
        HideActionBarAndTitleBar(this);
        //set view for activity
        SetContentView(Resource.Layout.activity_layout_home);

        HideNaviagtionBar(this);

        Window.DecorView.SystemUiVisibilityChange += (sender, e) =>
        {
            Window.DecorView.SystemUiVisibility = (Android.Views.StatusBarVisibility)Global.flags;
        };

    }
    public override void OnWindowFocusChanged(bool hasFocus)
    {
        base.OnWindowFocusChanged(hasFocus);
        Window.DecorView.SystemUiVisibility = (Android.Views.StatusBarVisibility)Global.flags;

    }
    public static void HideActionBarAndTitleBar(Activity activity)
    {
        //Remove title bar
        activity.RequestWindowFeature(WindowFeatures.NoTitle);
        //Remove notification bar
        activity.Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);
    }
    public static void HideNaviagtionBar(Activity activity)
    {
        View decorView = activity.Window.DecorView;
        decorView.SystemUiVisibility = (Android.Views.StatusBarVisibility)flags;

        decorView.SystemUiVisibilityChange += (object sender, View.SystemUiVisibilityChangeEventArgs e) =>
        {
            if (e.Visibility == (Android.Views.StatusBarVisibility)SystemUiFlags.Visible && SystemUiFlags.Fullscreen == SystemUiFlags.Visible)
            {
                decorView.SystemUiVisibility = (Android.Views.StatusBarVisibility)flags;
            }
        };
    }

I don't know why this is happening, please help.

Lalit Kumar
  • 146
  • 1
  • 6

0 Answers0