gpt4 book ai didi

c - 如何在 Xamarin Android 中隐藏/关闭软键盘?

转载 作者:太空宇宙 更新时间:2023-11-04 04:11:48 37 4
gpt4 key购买 nike

在我的程序中有一个标准键盘用于“输入”

但是我正在测试一些东西,我最终设置了 IsEnabled = True,但是当程序进入 Focus on that Entry 时,默认的 Android Softkeyboard 出现,我不希望它在我点击 Entry 时出现。

如何在 Entry 中不显示 SoftKeyboard?

        <Label Text="CÓD VENDEDOR:"
FontSize="Large"
FontAttributes="Bold"
TextColor="Black"/>

<Entry Placeholder="000000000000000"
Text="{Binding codVend}"
Keyboard="numeric"
MaxLength="15"
FontSize="Large"
FontAttributes="Bold"
IsEnabled="True"
TextColor="Black"
InputTransparent="False"/>

<Label Text="N LÓGICO:"
FontSize="Large"
FontAttributes="Bold"
TextColor="Black"/>

<Entry Placeholder="00000000"
Text="{Binding codTrn}"
Keyboard="Numeric"
MaxLength="8"
IsEnabled="True"
FontSize="Large"
FontAttributes="Bold"
TextColor="Black"
InputTransparent="False"/>

<StackLayout Padding="2"
HorizontalOptions="Center"
VerticalOptions="Center">

<ActivityIndicator IsVisible="{Binding IsBusy}"
IsRunning="{Binding IsBusy}"
Color="Blue"/>
<!-- Place new controls here -->

<StackLayout HorizontalOptions="Center"
VerticalOptions="Center"
Padding="5">

<Grid HorizontalOptions="Center"
VerticalOptions="Center">

<Grid.ColumnDefinitions>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
</Grid.ColumnDefinitions>
<!--Row 1-->
<Button Text="1"
BackgroundColor="Blue"
TextColor="White"
BorderRadius="10"
Grid.Column="0"
Grid.Row="0"
HeightRequest="60"
FontSize="Large"
FontAttributes="Bold"
HorizontalOptions="Center"
VerticalOptions="Center"
Command="{Binding NumericCommand}"
CommandParameter="1"/>
<Button Text="2"
BackgroundColor="Blue"
TextColor="White"
BorderRadius="10"
Grid.Column="1"
Grid.Row="0"
HeightRequest="60"
FontSize="Large"
FontAttributes="Bold"
HorizontalOptions="Center"
VerticalOptions="Center"
Command="{Binding NumericCommand}"
CommandParameter="2"/>
<Button Text="3"
BackgroundColor="Blue"
TextColor="White"
BorderRadius="10"
Grid.Column="2"
Grid.Row="0"
HeightRequest="60"
FontSize="Large"
FontAttributes="Bold"
HorizontalOptions="Center"
VerticalOptions="Center"
Command="{Binding NumericCommand}"
CommandParameter="3"/>
<Button Text="OK"
BackgroundColor="Green"
TextColor="White"
BorderRadius="10"
Grid.Column="3"
Grid.Row="0"
HeightRequest="60"
FontSize="Large"
FontAttributes="Bold"
HorizontalOptions="Center"
Grid.RowSpan="4"
Command="{Binding SaveCommand}"/>
<!--Row 2-->
<Button Text="4"
BackgroundColor="Blue"
TextColor="White"
BorderRadius="10"
Grid.Column="0"
Grid.Row="1"
HeightRequest="60"
FontSize="Large"
FontAttributes="Bold"
HorizontalOptions="Center"
VerticalOptions="Center"
Command="{Binding NumericCommand}"
CommandParameter="4"/>
<Button Text="5"
BackgroundColor="Blue"
TextColor="White"
BorderRadius="10"
Grid.Column="1"
Grid.Row="1"
HeightRequest="60"
FontSize="Large"
FontAttributes="Bold"
HorizontalOptions="Center"
VerticalOptions="Center"
Command="{Binding NumericCommand}"
CommandParameter="5"/>
<Button Text="6"
BackgroundColor="Blue"
TextColor="White"
BorderRadius="10"
Grid.Column="2"
Grid.Row="1"
HeightRequest="60"
FontSize="Large"
FontAttributes="Bold"
HorizontalOptions="Center"
VerticalOptions="Center"
Command="{Binding NumericCommand}"
CommandParameter="6"/>
<!--Row 3-->
<Button Text="7"
BackgroundColor="Blue"
TextColor="White"
BorderRadius="10"
Grid.Column="0"
Grid.Row="2"
HeightRequest="60"
FontSize="Large"
FontAttributes="Bold"
HorizontalOptions="Center"
VerticalOptions="Center"
Command="{Binding NumericCommand}"
CommandParameter="7"/>
<Button Text="8"
BackgroundColor="Blue"
TextColor="White"
BorderRadius="10"
Grid.Column="1"
Grid.Row="2"
HeightRequest="60"
FontSize="Large"
FontAttributes="Bold"
HorizontalOptions="Center"
VerticalOptions="Center"
Command="{Binding NumericCommand}"
CommandParameter="8"/>
<Button Text="9"
BackgroundColor="Blue"
TextColor="White"
BorderRadius="10"
Grid.Column="2"
Grid.Row="2"
HeightRequest="60"
FontSize="Large"
FontAttributes="Bold"
HorizontalOptions="Center"
VerticalOptions="Center"
Command="{Binding NumericCommand}"
CommandParameter="9"/>
<!--Row 4-->
<Button Text="X"
BackgroundColor="Red"
TextColor="White"
BorderRadius="10"
Grid.Column="0"
Grid.Row="3"
HeightRequest="60"
FontSize="Large"
FontAttributes="Bold"
HorizontalOptions="Center"
VerticalOptions="Center"
Command="{Binding ClearAllCommand}"/>
<Button Text="0"
BackgroundColor="Blue"
TextColor="White"
BorderRadius="10"
Grid.Column="1"
Grid.Row="3"
HeightRequest="60"
FontSize="Large"
FontAttributes="Bold"
VerticalOptions="Center"
Command="{Binding NumericCommand}"
CommandParameter="0"/>
<Button Text="C"
BackgroundColor="Yellow"
TextColor="White"
BorderRadius="10"
Grid.Column="2"
Grid.Row="3"
HeightRequest="60"
FontSize="Large"
FontAttributes="Bold"
HorizontalOptions="Center"
Command="{Binding ClearCommand}"/>
</Grid>
</StackLayout>
</StackLayout>
</StackLayout>
</ContentPage.Content>

最佳答案

Customizing an Entry在 Native android 中可以这样做:

首先,创建一个MyEntry

public class MyEntry : Entry
{
}

其次,在 Xaml 中使用:

<ContentPage ...
xmlns:local="clr-namespace:CustomRenderer;assembly=CustomRenderer"
...>
...
<local:MyEntry Text="In Shared Code" />
...
</ContentPage>

三、Android上Renderer中修改

using Xamarin.Forms.Platform.Android;

[assembly: ExportRenderer(typeof(MyEntry), typeof(MyEntryRenderer))]
namespace CustomRenderer.Android
{
class MyEntryRenderer : EntryRenderer
{
public MyEntryRenderer(Context context) : base(context)
{
}

protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);

if (Control != null)
{
Control.InputType = Android.Text.InputTypes.Null;
//Set input type be null, keyboard will never appear,even when click the Entry.If need show keyboard, this way also can be used.
//Control.InputType = Android.Text.InputTypes.ClassText;
}
}
}
}

关于c - 如何在 Xamarin Android 中隐藏/关闭软键盘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56466466/

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