我有自定义键盘的代码。
它的xamarin.forms for android。
我希望键盘从页面底部显示,并在需要时提高输入。
结果是键盘显示在页面顶部,如果条目位于顶部,则覆盖条目。
〜
public class CustomEntryRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control == null)
return;
Android.InputMethodServices.Keyboard numericKeyboard = new Android.InputMethodServices.Keyboard(Control.Context, Resource.Xml.keyboard2);
CustomKeyboardView numericKeyboardView = new CustomKeyboardView(Control.Context, null);
numericKeyboardView.Id = Control.Id;
numericKeyboardView.Keyboard = numericKeyboard;
numericKeyboardView.Visibility = ViewStates.Gone;
numericKeyboardView.PreviewEnabled = false;
/////////////////////////////////////////////////
// THIS IS THE LAYOUT CREATION
////////////////////////////////////////////////
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent); // maybe WrapContent on all
lp.Gravity = GravityFlags.Bottom;
lp.BottomMargin = 0;
/////////////////////////////////////////////////
Activity activity = this.Context as Activity;
activity.AddContentView(numericKeyboardView, lp);
Control.Touch += (sender, ex2) =>
{
if (numericKeyboardView.Visibility == ViewStates.Gone)
{
//Xamarin.Forms.Animation animation = Android.Views.Animations.AnimationUtils.LoadAnimation(
Android.Views.Animations.Animation animation = Android.Views.Animations.AnimationUtils.LoadAnimation(
this.Context,
Resource.Animation.slide_in_bottom
);
numericKeyboardView.ShowWithAnimation(animation);
numericKeyboardView.Visibility = ViewStates.Visible;
}
ex2.Handled = true;
};
}
}
〜
答案 0 :(得分:0)
我希望键盘从页面底部显示,并在需要时提高输入。
您需要使用RelativeLayout
包裹numericKeyboardView
并设置AlignParentBottom
规则。
在OnElementChanged
方法中,添加以下代码:
//Create RelativeLayout for Keyboard
Android.Widget.RelativeLayout rl = new Android.Widget.RelativeLayout(this.Context);
//Create the LayoutParams for Keyboard
Android.Widget.RelativeLayout.LayoutParams rlp = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.FillParent, LayoutParams.WrapContent);
//set the AlignParentBottom rule
rlp.AddRule(LayoutRules.AlignParentBottom);
//set the LayoutParams to Keyboard
numericKeyboardView.LayoutParameters = rlp;
//add the keyboard to RelativeLayout
rl.AddView(numericKeyboardView);
//get current activity
Activity activity = this.Context as Activity;
//Add the Layout View to activity
activity.AddContentView(rl,rlp);