我在EditText字段中设置了最大文本长度.
<EditText
android:id="@+id/courseDescriptionField"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:lines="5"
android:maxLength="@integer/max_course_description_limit"
android:gravity="left|top" >
</EditText>
Run Code Online (Sandbox Code Playgroud)
然而,问题是,文本STOPS出现在140个字符之后,但它仍然继续输入,除了文本没有出现,但是,它确实出现在"缓冲区"(意思是建议事物)中这就是你所说的.
作为旁注,我使用TextWatcher来跟踪限制.有没有办法完全限制文本的数量,所以当有140个字符时,按下退格/删除以外的其他内容时没有任何反应?
如何在聚焦EditText视图时删除边框?
我需要它,因为这个视图在屏幕上占用的空间很小,但没有边框就足够了.在模拟器上运行时,将显示橙色边框,在设备上显示蓝色边框.
我EditText在android中有一个视图.在此,我想检测向左或向右滑动.我可以使用下面的代码在空白区域获取它.但是当我滑动时,这不起作用EditText.我怎么做?如果我做错了,请告诉我.谢谢.
使用代码:
switch (touchevent.getAction())
{
case MotionEvent.ACTION_DOWN:
{
oldTouchValue = touchevent.getX();
break;
}
case MotionEvent.ACTION_UP:
{
float currentX = touchevent.getX();
if (oldTouchValue < currentX)
{
// swiped left
}
if (oldTouchValue > currentX )
{
swiped right
}
break;
}
}
Run Code Online (Sandbox Code Playgroud) 我的Android应用程序中有一堆EditTexts,每个都将InputMethod设置为numberSigned.我的目标设备没有硬件键盘,并使用软件键盘进行数字输入.Android使用"下一步"按钮替换输入框右侧的标准"完成"按钮.我怎样才能使用"完成"?
我正在尝试设置和onclicklistener,以便当我在edittext元素中单击时,它将清除其当前内容.这里有什么问题吗?当我编译这段代码时,我得到一个强制退出和ActivityManager:无法调度DDM块4d505251:没有处理程序定义的错误.
public class Project extends Activity implements OnClickListener {
/** Called when the activity is first created. */
EditText editText = (EditText)findViewById(R.id.editText1);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
editText.setOnClickListener(this);
setContentView(R.layout.main);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
editText.setText("");
}
}
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我所有屏幕的第一个视图是EditText,因此每次进入屏幕时,屏幕键盘都会弹出.如何禁用此弹出窗口并在手动单击EditText时启用它?
eT = (EditText) findViewById(R.id.searchAutoCompleteTextView_feed);
eT.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(eT.getWindowToken(), 0);
}
}
});
Run Code Online (Sandbox Code Playgroud)
xml代码:
<ImageView
android:id="@+id/feedPageLogo"
android:layout_width="45dp"
android:layout_height="45dp"
android:src="@drawable/wic_logo_small" />
<Button
android:id="@+id/goButton_feed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="@string/go" />
<EditText
android:id="@+id/searchAutoCompleteTextView_feed"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/goButton_feed"
android:layout_toRightOf="@id/feedPageLogo"
android:hint="@string/search" />
<TextView
android:id="@+id/feedLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/feedPageLogo"
android:gravity="center_vertical|center_horizontal"
android:text="@string/feed"
android:textColor="@color/white" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ButtonsLayout_feed"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:id="@+id/feedButton_feed"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_margin="0dp"
android:layout_weight="1"
android:background="@color/white"
android:text="@string/feed"
android:textColor="@color/black" />
<Button
android:id="@+id/iWantButton_feed"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_margin="0dp"
android:layout_weight="1" …Run Code Online (Sandbox Code Playgroud) 有没有办法让Multi-Line EditText出现并在Android 2.3上使用IME Action Label"Done"?
在Android 2.2中,这不是问题,输入按钮显示IME操作标签"完成"(android:imeActionLabel="actionDone"),并在单击时取消软输入.
配置EditText多线时,Android 2.3无法显示软输入键盘的"完成"操作.
我已经设法通过使用a来改变Soft Input输入按钮的行为KeyListener,但是enter按钮仍然看起来像一个回车键.
这是宣言 EditText
<EditText
android:id="@+id/Comment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="0dp"
android:lines="3"
android:maxLines="3"
android:minLines="3"
android:maxLength="60"
android:scrollHorizontally="false"
android:hint="hint"
android:gravity="top|left"
android:textColor="#888"
android:textSize="14dp"
/>
<!-- android:inputType="text" will kill the multiline on 2.3! -->
<!-- android:imeOptions="actionDone" switches to a "t9" like soft input -->
Run Code Online (Sandbox Code Playgroud)
inputType在加载后在活动中设置内容视图时检查值,它显示为:
inputType = 0x20001
Run Code Online (Sandbox Code Playgroud)
这是:
TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_NORMALInputType.TYPE_TEXT_FLAG_MULTI_LINE我想从Android中获取输入,URL或网站名称,例如www.google.com,EditText用户点击Button要提交,或者当EditText失去焦点时,应该验证URL,例如格式为" www.anyURL.com "......
我怎样才能做到这一点?Android中是否有任何内置功能?
我本质上是尝试以编程方式设置EditText的数字值.到目前为止,我有:
weightInput.setInputType(InputType.TYPE_CLASS_PHONE);
weightInput.setKeyListener(DigitsKeyListener.getInstance());
Run Code Online (Sandbox Code Playgroud)
这很好,但我也希望能够包含小数位(.).有任何想法吗?
所以我有一个似乎常见的问题,就是我的对话框中的EditText在获得焦点时不会显示出来.我已经看过几个解决方法,比如在这个帖子中,这一个和这一个(还有更多),但我从来没有见过一个令人满意的解释,为什么这首先发生.
我更倾向于让Android使用自己的EditTexts默认行为,而不是构建我自己的行为,但似乎每个人(在那些线程中)已经接受了Dialogs中EditTexts的默认行为是只给光标而没有键盘.那为什么会这样?
为了记录,这些解决方法似乎都没有对我有用 - 我最接近的是强制键盘出现在对话框下面(使用InputMethodManager.toggleSoftKeyboard(*)).我的特殊配置是API15,EditText显示在AlertDialog中ListView的页脚中.设置了EditText android:focusable ="true",onFocusChangeListener 正在接收焦点事件.
编辑:
根据要求,这是我正在使用的特定代码段.我不打算整个布局,但在这个特定的应用程序中,EditText响应于按下对话框上的按钮而出现(类似于动作视图).它包含在RelativeLayout中,默认情况下可见性"已消失":
<RelativeLayout
android:id="@+id/relLay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:visibility="gone"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp">
<ImageButton
android:id="@+id/cancelBut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@color/transparent"
android:src="@drawable/cancelButton"
android:layout_margin="5dp"/>
<ImageButton
android:id="@+id/okBut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/cancelBut"
android:background="@color/transparent"
android:src="@drawable/okButton"
android:layout_margin="5dp" />
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:focusable="true"
android:layout_toLeftOf="@id/okBut"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
构建它的代码将relativeLayout的可见性设置为"Visible"(并隐藏其他UI元素).根据我使用EditText的经验,这应该足以在EditText聚焦时拉起键盘.但是,出于某种原因,情况并非如此.我可以在onFocusChangeListener上设置以下内容:
edit_text.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// For whatever reason we need to request …Run Code Online (Sandbox Code Playgroud)