如何在毛伊岛使用#getSystemService?

问题描述 投票:0回答:0

我正在实施 Maui 应用程序,但遇到了当 Entry 控件获得焦点时不显示软键盘的错误。输入控件获得焦点,光标闪烁,键盘保持隐藏状态。
(反过来,隐藏键盘,我知道禁用/启用 hack。)
我尝试了很多东西,下一个是使用平台互操作来强制显示它。
我发现了一些使用

Context.getSystemService(Context.InputMethodManager) as InputMethodManager
的建议,但是 getSystemService 在 Maui 提供的 Android.Content.Context 对象上不可用。

因此,为了让我开始,有人可以帮助举例说明如何使用 Maui 的 getSystemService 来获取对 InputMethodManager 的引用吗?

XAML

<ContentPage.Content>
<ScrollView>
    <StackLayout x:Name="MainLayout"
        Padding="30,100">
        <Label Text="Password" />
        <Frame CornerRadius="15" Padding="0">
            <Entry x:Name="PinEntry" 
                Text="{Binding Pin}"
                FontSize="20"
                HorizontalTextAlignment="Center"
                Keyboard="Telephone"/>
        </Frame>
        <Button x:Name="LoginButton"
            Text="Log in"
            FontSize="20"
            Clicked="LoginButton_Clicked"
            Padding="12"
            Margin="0,30" />
    </StackLayout>
</ScrollView>
</ContentPage.Content>

代码隐藏

protected override async void OnAppearing()
{
    PinEntry.Focus();
    base.OnAppearing();
    PinEntry.Focus();
}
android interop maui inputmethodmanager
© www.soinside.com 2019 - 2024. All rights reserved.