此处将为大家介绍关于ajax–在JSF2中按Enter键时调用bean中的监听器:inputText的详细内容,并且为您解答有关js监听回车键的相关问题,此外,我们还将为您介绍关于AndroidMat
此处将为大家介绍关于ajax – 在JSF 2中按Enter键时调用bean中的监听器:inputText的详细内容,并且为您解答有关js监听回车键的相关问题,此外,我们还将为您介绍关于Android Material Design控件使用(2)——FloatButton TextInputEditText TextInputLayout 按钮和输入框、Android TextInputLayout 和 TextInputEditText 带有轮廓边框并在轮廓框上方显示提示文本、Android:在TextInputLayout中的EditText右侧显示TextView、asp.net – 按Enter键时提交表单的有用信息。
本文目录一览:- ajax – 在JSF 2中按Enter键时调用bean中的监听器:inputText(js监听回车键)
- Android Material Design控件使用(2)——FloatButton TextInputEditText TextInputLayout 按钮和输入框
- Android TextInputLayout 和 TextInputEditText 带有轮廓边框并在轮廓框上方显示提示文本
- Android:在TextInputLayout中的EditText右侧显示TextView
- asp.net – 按Enter键时提交表单
ajax – 在JSF 2中按Enter键时调用bean中的监听器:inputText(js监听回车键)
当用户在h:inputText元素中写入内容并按下回车按钮时,另一个h:inputText应该使用数据库中的某些数据进行更新.
我的testpage包含以下代码:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"> <h:body> <h3>JSF 2.0 Example</h3> <h:form> <h:inputText id="inputField" value="#{helloBean.name}"> <f:ajax render="output" execute="inputField" event="keypress" listener="#{bean.mychangelistener}" /> </h:inputText> <h2><h:outputText id="output" value="#{helloBean.name}" /></h2> </h:form> </h:body> </html>
Bean包含所有必要的getter和setter以及此函数:
public void myChangeEvent( AjaxBehaviorEvent event) { System.out.println( "VALUE CHANGED" ); }
更新2013-12-16:
经过数小时的故障排除后,我发现了为什么在离开文本字段或在文本字段中按Enter键时没有提交任何内容的问题.我的Web应用程序是使用模板创建的,在我的页面标题的模板中是一个’a4j:status’标签,这与JSF 2冲突.删除’a4j:status’行后,当我点击时调用myChangeEvent方法编辑文本字段值后,在网页上的其他位置.
但是存在的问题是,在更改文本字段值后单击enter时整个页面都会被提交.这是因为我在页面底部有一个按钮,用于保存用户输入,因此提交整个页面,这是正常的.但是在文本字段中按Enter键时不应调用此按钮.我必须添加到现有代码中?
更新2013-12-17:
在JS遇到麻烦之后我终于在L-Ray的帮助下工作了(再次感谢).
在这里,我将展示使用JQuery的最终版和工作版:
<h:inputText id="inputField" value="#{helloBean.name}" > <f:ajax render="output" execute="inputField" event="change" listener="#{helloBean.myChangeEvent}" /> </h:inputText> <h2><h:outputText id="output" value="#{helloBean.name}" /></h2> <script type="text/javascript"> $(document).ready(function() { $( "#mainForm\\:inputField" ).bind('keypress',function(e) { var keyCcode = e.keyCode || e.which; // Enter was pressed if(keyCcode == 13) { e.target.blur(); e.stopPropagation(); return false; } else { return true; } }); }); </script>
解决方法
另外我建议不要在f:ajax中听一个keypressed-event,而是在javascript – keypress – 事件中听一个更改事件.
因此,作为解决方案,以下代码可能适合您…
<h:form> <h:inputText id="inputField" value="#{helloBean.name}" onkeypress="if (event.keyCode == 13) {event.target.blur();event.stopPropagation();return false;} else {return true;};"> <f:ajax render="output" execute="inputField" event="change" listener="#{helloBean.myChangeEvent}"/> </h:inputText> <h2><h:outputText id="output" value="#{helloBean.name}" /></h2> </h:form>
托管bean
public void myChangeEvent( AjaxBehaviorEvent e ) { System.out.println( "VALUE CHANGED" ); }
event
object将由浏览器本身提供给我们的javascript部分 – 因此在on * – 属性外部运行将无效.
javascript方法event.stopPropagation()是一个jQuery method或seamingly也是一个javascript方法(见W3C school),防止其他事件被调用冒泡DOM树.
Android Material Design控件使用(2)——FloatButton TextInputEditText TextInputLayout 按钮和输入框
FloatingActionButton
1. 使用FloatingActionButton的情形
FAB代表一个App或一个页面中最主要的操作,如果一个App的每个页面都有FAB,则通常表示该App最主要的功能是通过该FAB操作的。
为了突出FAB的重要性,一个页面最好只有一个FAB 使用的时候需要导入desgin包,Android Studio 新版本都已经自动导入了,这里就不多说
compile ''com.android.support:design:25.1.0''
2. FloatingActionButton的大小一般有两种大小(官方)
- 56 * 56dp :默认的大小,最常用的尺寸。
- 40 * 40 dp :Mini版。 当然也是可以改变大小,不过一般使用
按钮中间图标大小官方推荐为 24*24dp
3.FloatingActionButton的属性
FloatingActionButton是继承ImageView
,包含了ImageView
的所有属性,除此之外,还有几个新增加的特殊属性,需要使用命名空间来使用。
引入命名空间:xmlns:app="http://schemas.android.com/apk/res-auto"
属性名 | 说明 |
---|---|
elevation | 阴影的高度 |
fabSize | FAB的大小,为normal时,大小为:56 * 56dp ,为mini时,大小为: 40 * 40 dp |
backgroundTint | FAB的背景颜色 |
rippleColor | 点击FAB时,形成的波纹颜色 |
TextInputEditText
介绍
TextInputEditText
是EditText
的子类,相当于完善了有些EditText
的缺点
当我们的界面处于全屏时,点击一个
EditText
,默认情况下不是在它下面弹出键盘,而是进入到输入法的一个全屏的输入界面(通过配置android:imeOptions=”flagNoExtractUi”可以设为直接在当前界面显示)
如果我们给
EditText
套上了一个TextInputLayout
时,TextInputLayout
会拿到EditText
的hint
显示出来并把EditText
本身的hint
设为空.这样我们在全屏的输入界面上,就显示不出来我们设置hint
,因此TextInputEditText
重写了EditText
TextInputLayout
介绍
这个布局其实是与EditText连用,可以实现密码框的显示与隐藏,和点击输入的时候,会将提示文字浮现在上方
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
tools:context="com.wan.homework.activity.Homework1Activity">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="用户名"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:inputType="textPassword"
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="密码"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
错误提示
TextInputLayout其实内置了一个用来显示错误提示的方法,方法名为setError
,效果如下
我们可以按钮的点击事件中,对用户的输入进行判断,从而显示错误信息
val userName = input_login_name.editText?.text.toString()
//验证用户输入
if (userName.isBlank()) {
input_login_name.error = "用户名还未输入哦!"
}
PS:如果想要清空错误信息,将错误信息设置为""
即可
input_login_name.error = ""
密码的显示与隐藏
如果想要实现此效果,只需要在将TextInputLayout的EditText的inputType
属性设置为textpassword
,将TextInputLayout的自定义属性passwordToggleEnabled
设置为true
即可
<android.support.design.widget.TextInputLayout
android:id="@+id/input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="密码"
android:inputType="textPassword"/>
</android.support.design.widget.TextInputLayout>
属性
属性名 | 说明 |
---|---|
app:Theme | 设置下划线或其他的颜色属性 |
android.support.design:counterEnabled | 是否显示计数器 |
android.support.design:counterMaxLength | 设置计数器的最大值,与counterEnabled同时使用 |
android.support.design:counterTextAppearance | 计数器的字体样式 |
android.support.design:counterOverflowTextAppearance | 输入字符大于我们限定个数字符时的字体样式 |
android.support.design:errorEnabled | 是否显示错误信息 |
android.support.design:errorTextAppearance | 错误信息的字体样式 |
android.support.design:hintAnimationEnabled | 是否显示hint的动画,默认true |
android.support.design:hintEnabled | 是否使用hint属性,默认true |
android.support.design:hintTextAppearance | 设置hint的文字样式(指运行动画效果之后的样式) |
android.support.design:passwordToggleDrawable | 设置密码开关Drawable图片,于passwordToggleEnabled同时使用 |
android.support.design:passwordToggleEnabled | 是否显示密码开关图片,需要EditText设置inputType |
android.support.design:passwordToggleTint | 设置密码开关图片颜色 |
android.support.design:passwordToggleTintMode | 设置密码开关图片(混合颜色模式),与passwordToggleTint同时使用 |
原文出处:https://www.cnblogs.com/stars-one/p/10348492.html
Android TextInputLayout 和 TextInputEditText 带有轮廓边框并在轮廓框上方显示提示文本
如何解决Android TextInputLayout 和 TextInputEditText 带有轮廓边框并在轮廓框上方显示提示文本?
我在我的应用程序中使用 TextInputLayout 和 TextInputEditText 作为用户输入,但现在我们需要不同的设计,如下图所示。我的意思是提示文本应该在轮廓框上方而不是在轮廓边框内。我确实尝试了几种方法,但无法确定可以帮助我实现这种 UI 的确切属性或样式。
- 预期的用户界面:
- 当前用户界面:
- 样式:
<style name="TextInputLayoutAppearance"parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
<item name="BoxstrokeColor">@color/text_input_Box_stroke_color</item>
<item name="shapeAppearanceOverlay">
@style/TextInputLayoutMaterialThemeRoundedShapeAppearanceOverlay
</item>
<item name="hintTextColor">@color/hint_color</item>
<item name="android:textColorHint">@color/hint_text</item>
</style>
<style name="TextInputLayoutMaterialThemeRoundedShapeAppearanceOverlay" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">@dimen/_8sdp</item>
</style>
我不确定这是否可以通过样式实现,或者需要开发结合 TextView 和 TextInput 控件的自定义控件。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
Android:在TextInputLayout中的EditText右侧显示TextView
在上图中,密码字段位于TextInputLayout中,右侧还有一个TextView,指向忘记密码活动.
我使用相对布局,在没有TextInpt布局的情况下使用Textview实现EditText,如下所示
Code – xml file
<EditText android:id="@+id/email_address" android:layout_width="match_parent" android:layout_height="wrap_content" android:drawableLeft="@drawable/ic_email" android:drawableStart="@drawable/ic_email" android:drawablePadding="10dp" android:hint="@string/email_address" android:textSize="14sp" android:maxLines="1" android:inputType="textEmailAddress" /> <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <EditText android:id="@+id/etxt_password_login" android:layout_width="match_parent" android:layout_height="wrap_content" android:drawableLeft="@drawable/ic_password" android:drawableStart="@drawable/ic_password" android:drawablePadding="10dp" android:textSize="14sp" android:hint="Password" android:layout_alignParentLeft="true" android:inputType="textPassword" android:maxLines="1"/> <TextView android:id="@+id/txt_forget_password" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:text="forget ?" android:textSize="12sp" android:layout_marginRight="10dp" android:textColor="#808080" /> </RelativeLayout>
但是,如果我在EditText中添加TextInputLayout,我无法实现它..尝试并搜索了很多.
?我们如何解决上述问题
谢谢..
解决方法
<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Password"/> </android.support.design.widget.TextInputLayout> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:text="Forgot Password ?"/> </RelativeLayout>
注意:为编辑文本设置一些填充以进行对齐
asp.net – 按Enter键时提交表单
我怎样才能做到这一点?
解决方法
<form id="Form1" defaultbutton="SubmitButton" runat="server">
关于ajax – 在JSF 2中按Enter键时调用bean中的监听器:inputText和js监听回车键的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于Android Material Design控件使用(2)——FloatButton TextInputEditText TextInputLayout 按钮和输入框、Android TextInputLayout 和 TextInputEditText 带有轮廓边框并在轮廓框上方显示提示文本、Android:在TextInputLayout中的EditText右侧显示TextView、asp.net – 按Enter键时提交表单等相关内容,可以在本站寻找。
本文标签: