I'm working on a little personal todo list app and so far everything has been working quite well. There is one little quirk I'd like to figure out. Whenever I go to add a new item, I have a Dialog with an EditText view showing inside. When I select the EditText view, the keyboard comes up to enter text, as it should. In most applications, the default seems to be that the shift key is held for the first letter... although it does not do this for my view. There has to be a simple way to fix, but I've searched the reference repeatedly and cannot find it. I'm thinking there has to be an xml attribute for the reference loaded by the Adapter, but I can't find out what it is.
当前回答
对于EditText中的资本化,您可以选择以下两种输入类型:
android:inputType=“textCapSentences” android:inputType=“textCapWords”
textCapSentences 这将使每个句子中第一个单词的第一个字母成为大写字母。
textCapWords 这将使每个单词的第一个字母作为大写字母。
如果你想要两个属性都使用|符号
android:inputType="textCapSentences|textCapWords"
其他回答
使用此代码仅第一个字母大写的EditText
MainActivity.xml
<RelativeLayout 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:layout_height="match_parent">
<EditText
android:id="@+id/et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:tag="true">
</EditText>
</RelativeLayout>
MainActivity.java
EditText et = findViewById(R.id.et);
et.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2)
{
if (et.getText().toString().length() == 1 && et.getTag().toString().equals("true"))
{
et.setTag("false");
et.setText(et.getText().toString().toUpperCase());
et.setSelection(et.getText().toString().length());
}
if(et.getText().toString().length() == 0)
{
et.setTag("true");
}
}
public void afterTextChanged(Editable editable) {
}
});
在XML和JAVA文件中设置输入类型,
在XML中,
android:inputType=“textMultiLine|textCapSentences”
它也将允许多行和在JAVA文件,
edittext.setRawInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
确保你键盘的自动大写设置是启用的。
以前它是android:capitalize="words",现在已弃用。建议使用android:inputType="textCapWords"
请注意,这将只在您的设备键盘自动大写设置启用。
要通过编程实现,请使用以下方法:
setInputType (InputType。TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
在XML编辑文本中应用以下行。
android:inputType="textCapSentences|textMultiLine"
它还允许多线支持。
对于EditText中的资本化,您可以选择以下两种输入类型:
android:inputType=“textCapSentences” android:inputType=“textCapWords”
textCapSentences 这将使每个句子中第一个单词的第一个字母成为大写字母。
textCapWords 这将使每个单词的第一个字母作为大写字母。
如果你想要两个属性都使用|符号
android:inputType="textCapSentences|textCapWords"
推荐文章
- 警告:API ' variable . getjavacompile()'已过时,已被' variable . getjavacompileprovider()'取代
- 安装APK时出现错误
- 碎片中的onCreateOptionsMenu
- TextView粗体通过XML文件?
- 如何使线性布局的孩子之间的空间?
- DSL元素android.dataBinding。enabled'已过时,已被'android.buildFeatures.dataBinding'取代
- ConstraintLayout:以编程方式更改约束
- PANIC: AVD系统路径损坏。检查ANDROID_SDK_ROOT值
- 如何生成字符串类型的buildConfigField
- Recyclerview不调用onCreateViewHolder
- Android API 21工具栏填充
- Android L中不支持操作栏导航模式
- 如何在TextView中添加一个子弹符号?
- PreferenceManager getDefaultSharedPreferences在Android Q中已弃用
- 在Android Studio中创建aar文件