我在MarshMallow设备上进行了测试。当我写了XML EditText和集PaddingBottom来Retype EditText。但它不起作用。但是,当我设置PaddingLeft到New PassWord EditText工作正常。
xml代码:
<EditText
android:id="@+id/change_password_old_password_edittext"
android:layout_below="@+id/change_password_mobileNumber_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Old Password"
android:layout_marginTop="20.0dip"
android:textColorHint="#40000000"
android:textSize="@dimen/textsize16"/>
<EditText
android:id="@+id/change_password_new_password_edittext"
android:layout_below="@+id/change_password_old_password_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="New Password"
android:layout_marginTop="20.0dip"
android:textColorHint="#40000000"
android:paddingLeft="10dip"
android:textSize="@dimen/textsize16"/>
<EditText
android:id="@+id/change_password_retype_password_edittext"
android:layout_below="@+id/change_password_new_password_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Retype Password"
android:layout_marginTop="20.0dip"
android:paddingBottom="10dip"
android:textColorHint="#40000000"
android:textSize="@dimen/textsize16"/>
Run Code Online (Sandbox Code Playgroud)
屏幕截图:
然后,我决定以PaddingBottom编程方式进行设置。但是它给出了奇怪的输出。
Java代码:
内部OnCreate方法
EditText change_password_retype_password_edittext = (EditText)findViewById(R.id.change_password_retype_password_edittext);
change_password_retype_password_edittext.setPadding(0,0,0,10);
Run Code Online (Sandbox Code Playgroud)
输出:
注: 我已经测试上
Marshmallow,LolliPop也Jellybean。但是在所有设备上都无法正常工作。
嗨,我试图在点击监听器上添加editText,以便当用户使用下面的代码单击edittext时,我可以禁用软键盘,该怎么做?
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);
Run Code Online (Sandbox Code Playgroud) 在iOS中TextField有一个名为Appeareancecan 的属性Dark值.它将改变KEYBOARD颜色,(不是文本域itsels)但是在Android中我找不到适合EditText的颜色,将键盘颜色改为黑色或黑色.
我需要读取应用程序的条形码。我为此使用了触发条码扫描器。通过USB进行通讯。
如您所知,条形码扫描仪的工作原理类似于键盘。当设备读取条形码时,它将尝试将值写入具有焦点的输入。然后,用户按下触发器,条形码扫描器便会工作,直到成功读取条形码为止。然后,它进入待机模式。读取大量条形码的理想方法。
问题在于,用户按下触发器并读取条形码后,EditText的焦点消失了。焦点将随机转到同一布局中的另一个视图。当用户尝试再读取一个条形码时,该操作失败,因为没有关注相关的EditText。
我尝试了什么?
android:windowSoftInputMode="stateAlwaysVisible"
Run Code Online (Sandbox Code Playgroud)
将以上行添加到清单文件
android:focusable="true"
android:focusableInTouchMode="true"
Run Code Online (Sandbox Code Playgroud)
在xml端添加了以上几行。
edtBarcode.setOnFocusChangeListener(new View.OnFocusChangeListener()
{
@Override
public void onFocusChange(View v, boolean hasFocus)
{
if (!hasFocus)
{
//find the view that has focus and clear it.
View current = getCurrentFocus();
if (current != null)
{
current.clearFocus();
}
edtBarcode.requestFocus();
}
}
});
Run Code Online (Sandbox Code Playgroud)
它检测EditText何时失去焦点。但是我不能把它分配回来。我确保EditText在触摸模式下可聚焦。
我该如何解决?
handlerFocus = new Handler();
final int delay = 1000; //milliseconds
handlerFocus.postDelayed(new Runnable()
{
public void run()
{
edtBarcode.requestFocus();
handlerFocus.postDelayed(this, delay);
}
}, delay);
Run Code Online (Sandbox Code Playgroud)
我知道这个解决方案不好。那么,如何在不打开键盘的情况下使焦点始终保持在同一EditText中呢?
我知道有类似这样的问题,我一直在这里发布了很多代码来达到这一点,但它们都没有适用于我的适配器.我也没有使用ViewHolders像许多其他人做,因为我真的不明白他们是什么.
在我的适配器类中,我想编辑一个editText以更改其ArrayList事件对象中的相应值.但是现在改变一个事件EditText字段会改变它们,即使我使用了mobileArrayList.get(position).
public class CustomAdapter extends ArrayAdapter {
ArrayList<Event> mobileArrayList;
public CustomAdapter (Context context, ArrayList<Event> events){
super(context, 0, events);
this.mobileArrayList = events;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent){
Event event = mobileArrayList.get(position);
//ViewHolder holder;
if(convertView == null){
//holder = new ViewHolder();
// holder.caption = (EditText) convertView.findViewById(R.id.events);
convertView = LayoutInflater.from(getContext()).inflate(R.layout.listview_row, parent, false);
} else {
//holder = (ViewHolder) convertView.getTag();
}
EditText events = (EditText) …Run Code Online (Sandbox Code Playgroud) 我现在面临的一个问题是,当我定义EditText为password类型,并查看我的屏幕在阿拉伯语密码字段提示文本显示在左侧,而不是右侧[即预期.
以上是我得到的结果.我需要密码提示文本从右侧开始,这是阿拉伯语着作开始的地方.我也试过添加文字引力但没有运气.
正如我在问题中提到的,我正在尝试更改EditText中的提示字体.但我似乎无法实现它!
这是我获取用户名的EditText的代码:
<!-- Email Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:id="@+id/input_username_id"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="20dp">
<EditText
android:id="@+id/input_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:hint="@string/hint_username"
android:layout_marginRight="10dp"
android:gravity="right" />
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的java代码:
_usernameText = (EditText) (findViewById(R.id.input_username));
font = Typeface.createFromAsset(getAssets(), "fonts/ir.ttf");
_usernameText.setTypeface(font);
Run Code Online (Sandbox Code Playgroud)
这并没有改变EditText的提示字体.我尝试了其他解决方案而没有任何改变. http://chintanrathod.com/customizing-textinputlayout-part-2/
我希望你能帮助我解决我现在面临的问题.
我使用TextInputEditText创建了一个自定义搜索视图,它实际上非常简单,并且除了5.1(Lollipop)之外的所有Android版本都能正常工作,EditText在写入时甚至不会隐藏提示甚至显示光标,文本也不是可见.
我已经尝试过我所知道的一切,但我无法想象它会是什么.
非常感谢您的参与.
这是我的自定义类视图:
public class CustomSearchView extends RelativeLayout {
@BindView(R.id.csvIcon) ImageView csvIcon;
public @BindView(R.id.csvEditText) TextInputEditText editText;
public CustomSearchView(Context context) {
super(context);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.custom_search_view, this, true);
ButterKnife.bind(this);
}
public CustomSearchView(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.custom_search_view, this, true);
ButterKnife.bind(this);
TypedArray typedArray = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.CustomSearchView,
0, 0);
String hintText = typedArray.getString(R.styleable.CustomSearchView_hintText);
try {
int max = typedArray.getInteger(R.styleable.CustomSearchView_csv_length, 17);
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(max)});
editText.setInputType(typedArray.getInt(R.styleable.CustomSearchView_android_inputType, InputType.TYPE_CLASS_TEXT));
editText.setHint(hintText);
csvIcon.setImageDrawable(typedArray.getDrawable(R.styleable.CustomSearchView_csv_icon));
} catch (Exception e) …Run Code Online (Sandbox Code Playgroud) java android android-edittext android-5.0-lollipop android-textinputedittext
我正在编写一个小型计算器.
我有3个edittext字段,这些字段写成如下:
<EditText
android:id="@+id/zField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:hint="c"
android:ems="10"
android:gravity="right|bottom"
android:inputType="numberDecimal" />
Run Code Online (Sandbox Code Playgroud)
当我尝试输入一个否定小数时," - "就不会出现,所以我不能输入任何否定数字.我该如何解决?
我的一种应用程序布局中有一个“编辑文本”,并且我希望此EditText仅在实际被触摸时才打开键盘(我相信这被称为“专注于?”)。
截至目前,每当应用程序打开时,键盘就会与EditText一起打开,这不是我想要的。
我尝试了许多不同的XML标记来解决此问题:
android:focusable="false" <--- Prevents keyboard from opening at all.
android:focusable="true"
android:focusableInTouchMode = "true" <--- These tags give me the same result as no tags (keybaord will open on activity start)
android:focusedByDefault = "true" <--- Only available in API >= 23
Run Code Online (Sandbox Code Playgroud)
我要问的是,为什么很难禁用EditText的默认焦点?当然,我缺少执行此操作的简单方法。
编辑:将此行添加到我的AndroidManifest中解决了此问题:android:windowSoftInputMode =“ stateHidden”但是,我不喜欢此解决方案。似乎因为这是在清单中,所以它将影响比我需要更改的单个EditText更多的UI元素。
android ×10
android-edittext ×10
java ×3
xml ×2
arraylist ×1
focus ×1
fonts ×1
input ×1
listview ×1
uitextfield ×1