我希望有一些像这样的布局
[text tabel][edittext]
Run Code Online (Sandbox Code Playgroud)
我找不到像html esque标签这样的属性.似乎是我需要使用的情况
[TextView][EditText]
Run Code Online (Sandbox Code Playgroud)
但我不能让他们在同一行,这是我的xml文件.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/boat_1"/>
<EditText
android:id="@+id/entry"
android:hint="@string/IRC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/boat_2"/>
<EditText
android:id="@+id/entry"
android:hint="@string/IRC"
android:minWidth="100dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"/>
<Button android:id="@+id/close"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="@string/title_close" />
Run Code Online (Sandbox Code Playgroud)
为了设置EditText我们使用的单行,android:singleLine="true"但我想为提示文本设置单行,它很大,我想在一行中显示它,如:
我使用以下代码:
<EditText android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/defaultUrl"
android:singleLine="true" />
Run Code Online (Sandbox Code Playgroud)
注意:defaultUrl是动态且非常长的URL.
如何在EditText上键入时按下后退键的事件?当显示虚拟键盘并且用户按下时,它将被隐藏.我想处理此事件,但在EditText中设置OnKeyListener没有帮助.
我正在使用几个EditTexts 在Android上进行对话.onCreate()为了禁用软键盘,我把这一行放在了:
Keypad.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Run Code Online (Sandbox Code Playgroud)
问题是它只在对话框出现时无效.当我移动到下一个时EditText,键盘出现而不是下降.
有人知道如何解决这个问题吗?
我有一个numberDecimal EditText,我想用正则表达式验证.在验证中我想要的是:
在小数点之前,我要输入的最大数字是3,数字不应该像零一样从零开始2,23,342,等等.
小数点后,我想进入的最大数字是一个像.1,.3,.6等等.
所以,我允许用户输入的数字一样2.1,32.5,444.8,564.9,等.
但在我的代码中,会发生什么:
它允许用户在小数点前输入超过三位数更像是3456,4444,5555之后,它不会让我以后输入小数点.
它允许我0在小数点之前输入数字的开头.
那么为什么会发生这种情况,我使用的正则表达式有什么不对吗?如果有人知道,请帮我解决这个问题.
我用过的代码:
weightEditText.addTextChangedListener(new TextWatcher()
{
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s)
{
Pattern mPattern = Pattern.compile("^([1-9][0-9]{0,2})?(\\.[0-9]?)?$");
Matcher matcher = mPattern.matcher(s.toString());
if(!matcher.find())
{ …Run Code Online (Sandbox Code Playgroud) 我是Android开发的新手.在我的项目中,我正在使用EditText,但我想强制它只接受整数或浮点值.我怎样才能做到这一点?
我遇到了最新的Jelly Bean模拟器的行为问题.EditTexts我的应用程序中有几个.OnEditorActionListener当用户按下键盘上的ENTER键时,An 提供特殊处理.这一直到ICS,但现在在Jelly Bean上,侦听器回调方法onEditorAction()不再被调用.只插入一个新行EditText.
这可以通过这种方式复制:
EditText testEditText = new EditText(context);
testEditText.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Log.d(TAG, "onEditorAction() called");
return false;
}
});
addView(testEditText);
Run Code Online (Sandbox Code Playgroud)
这是Jelly Bean中的一个错误吗?还是在模拟器中?或者有意改变了行为?
奇怪的是,其他人写道,该方法被调用,但带有意外的参数,在这里运行Jelly Bean的Nexus 7:onEditorAction()中的null keyevent和actionid = 0(Jelly Bean/Nexus 7)
android android-virtual-device android-edittext android-4.2-jelly-bean
如何在android编辑文本中设置光标位置?我有一个编辑文本,在创建时我想在文本中间的某些时候将光标设置为某些时间,我该怎么办?
我的编辑文字如下:
android:id="@+id/editText11"
android:layout_width="wrap_content"
android:layout_height="200sp"
android:layout_above="@+id/horizontalScrollView1"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:gravity="top"
android:background="#00000000"
android:inputType="textMultiLine"
android:singleLine="true"
Run Code Online (Sandbox Code Playgroud) 大家好我有一个edittext,我想在我的Editttext中编写电子邮件验证,这是一个xml代码
<EditText
android:id="@+id/mail"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignLeft="@+id/phone"
android:layout_below="@+id/phone"
android:layout_marginRight="33dp"
android:layout_marginTop="10dp"
android:background="@drawable/edit_background"
android:ems="10"
android:hint="E-Mail"
android:inputType="textEmailAddress"
android:paddingLeft="20dp"
android:textColor="#7e7e7e"
android:textColorHint="#7e7e7e" >
</EditText>
Run Code Online (Sandbox Code Playgroud)
这是一个java代码
emailInput = mail.getText().toString().trim();
emailPattern = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
if (emailInput.matches(emailPattern)) {
Toast.makeText(getActivity(), "valid email address", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(), "Invalid email address", Toast.LENGTH_SHORT).show();
mail.setBackgroundResource(R.drawable.edit_red_line);
}
Run Code Online (Sandbox Code Playgroud)
我无法验证.烤面包消息总是"无效的电子邮件地址"我做错了什么?如果有人知道解决方案,请帮助我
在我的应用程序中,当用户单击或触摸"编辑文本"视图时,焦点有时会设置为开头.例如,如果现有文本为"Hi".用户想要点击它并将其更改为"H1你好吗?" 添加文字"你好吗?".但由于焦点在一开始,它就变成了"你好吗?嗨".因此,我总是希望在选择时将焦点设置为最正确的文本.我该怎么做呢.如果可能的话,请告诉我一些样品.感谢您的时间和帮助.