我正在使用AlertDialog.Builder来显示一个提示用户输入密码的对话框,然后我想在偏好中保存该密码,但是我无法弄清楚如何从警告对话框的输入方法中获取结果.
这基本上是我希望能够做到的:
String result;
AlertDialog.Builder b = new AlertDialog.Builder(this);
b.setTitle("Please enter a password");
final EditText input = new EditText(this);
b.setView(input);
b.setPositiveButton("OK", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int whichButton)
{
//I get a compile error here, it wants result to be final.
result = input.getText().toString();
}
});
b.setNegativeButton("CANCEL", null);
b.create().show();
Run Code Online (Sandbox Code Playgroud)
但是,我愿意做一些事情,比如showDialog(int);然后使用onCreateDialog(int)方法并以某种方式设置结果并以其他方法接收它,但我不知道如何去做最后一部分.
我正在尝试EditText使用软键进行编辑时具有以下特征.我准备了文档,在这里搜索,玩参数但找不到工作配置.
EditView屏幕上的视图有几行高度(例如3-4).我可以实现{1,2,3}和{1,2,4}但不能实现{1,2,3,4}.我的理由是,由于内容是单行(没有换行符),因此不使用Enter键,因此应该能够更改为Done标签.
我的设置代码如下所示
editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE);
editText.setHorizontallyScrolling(false);
editText.setSingleLine(false);
// This does not work. Soft keyboard has Enter action.
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
Run Code Online (Sandbox Code Playgroud)
可能吗?有什么建议吗?
是否可以更改EditText字段中显示的提示的字体?我想在xml本身设置字体.
我用a EditText来取消用户的日期.因此,当我在我给出的默认值上运行我的应用程序时,它将文本用红色加下划线.
XML代码
<EditText
android:id="@+id/setDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center_horizontal"
android:text="dd/mm/yyyy" />
Run Code Online (Sandbox Code Playgroud)
在我的活动中
date.setFocusableInTouchMode(false);
Run Code Online (Sandbox Code Playgroud)
为什么用红色强调文字?一旦设置了日期,它就不会显示红色下划线.
我需要在textview中放置一些图标,但它们不符合行高(请看箭头):

我试过这个:
spannable.setSpan(new ImageSpan(context, entry.getValue(), ImageSpan.ALIGN_BOTTOM), Matcher.start(), matcher.end(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
t.setText(spannable, BufferType.SPANNABLE);
Run Code Online (Sandbox Code Playgroud)
还有这个:
Drawable myIcon = c.getResources().getDrawable(R.drawable.myicon);
myIcon.setBounds(0, 0, myIcon.getIntrinsicWidth(), myIcon.getIntrinsicHeight());
spannable.setSpan(new ImageSpan(myIcon, ImageSpan.ALIGN_BASELINE), matcher.start(), matcher.end(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
t.setText(spannable, BufferType.SPANNABLE);
Run Code Online (Sandbox Code Playgroud)
在这两种情况下我都有相同的结果.
我将图标保存在/ res/drawable文件夹中,其大小为75x75px.我试图降低图像分辨率,但它们看起来很模糊
我不断收到这个错误,当我试图setErrorEnabled在我的textInputLayout:
03-12 12:29:03.206 5706-5706/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp, PID: 5706
java.lang.RuntimeException: Failed to resolve attribute at index 24
at android.content.res.TypedArray.getColor(TypedArray.java:401)
at android.widget.TextView.<init>(TextView.java:696)
at android.widget.TextView.<init>(TextView.java:632)
at android.widget.TextView.<init>(TextView.java:628)
at android.widget.TextView.<init>(TextView.java:624)
at android.support.design.widget.TextInputLayout.setErrorEnabled(TextInputLayout.java:380)
at com.bekwaai.popupwindow.RGNamePopUp$1.onClick(RGNamePopUp.java:48)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Run Code Online (Sandbox Code Playgroud)
这是场景 - 我有一个textInputLayout内部popupwindow.这是popupwidow中的代码.
public class NamePopUp extends PopupWindow {
android.support.v7.widget.AppCompatEditText name;
TextInputLayout nameInput;
public NamePopUp(final Context context) …Run Code Online (Sandbox Code Playgroud) android android-edittext android-popupwindow android-textinputlayout
尝试从EditText获取double值并在将它们传递给另一个Intent之前对其进行操作.不使用原始数据类型,所以我可以使用toString方法.
问题是当我包含蛋白质= Double.valueOf(p).doubleValue(); 样式命令,程序强制立即关闭而不在logcat中留下任何信息.如果我将它们注释掉并设置一些虚拟数据,如protein = 1.0; 它没有任何问题.原始数据类型和解析double也是如此.此代码与普通java中的虚拟数据完美配合.我究竟做错了什么?
EditText txtProt, txtCarb, txtFat, txtFiber, txtPoints;
String p, c, f, fi;
Double protein, carbs, fat, fiber;
double temp;
Integer points;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.v("Create Prompt", "ready for layout");
setContentView(R.layout.main);
Log.v("Layout Created", "ready for variable assignment");
txtProt = (EditText) findViewById(R.id.Protein);
txtCarb = (EditText) findViewById(R.id.Carbs);
txtFat = (EditText) findViewById(R.id.Fat);
txtFiber = (EditText) findViewById(R.id.Fiber);
txtPoints = (EditText) findViewById(R.id.Points);
btnCalc = (Button) findViewById(R.id.Calc);
Log.v("Variables Assigned", "ready for double assignment");
p = txtProt.getText().toString();
c …Run Code Online (Sandbox Code Playgroud) 当用户在EditText中键入时,我使用以下代码执行搜索:
EditText queryView = (EditText) findViewById(R.id.querybox);
queryView.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
triggerSearch(s.toString());
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
Run Code Online (Sandbox Code Playgroud)
但是,当用户键入单词时,这会多次触发.也就是说,如果用户输入"hello",则此代码将触发5次值("h","he","hel","hell","hello").通常情况下,这样会很好但是触发搜索很昂贵,而且我不想在没有太大用处的中间搜索上浪费资源.我想要的是在用户开始输入后仅触发某个阈值的侦听器,或者在调用之前在侦听器中等待的某种框架,triggerSearch如果在该等待之前触发了另一个事件,则取消自身.
我有一个EditText声明如下.
<EditText
android:layout_margin="2dip"
android:singleLine="true"
android:lines="1"
android:maxLines="1"
android:cursorVisible="true"
android:textCursorDrawable="@drawable/Black"
android:textColor="@color/black"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:background="@android:drawable/editbox_background"
/>
Run Code Online (Sandbox Code Playgroud)
但是在获得焦点时它不会显示光标.当我开始输入时,它显示第一个索引的光标.我希望即使在空的edittext中也能显示光标.
我已经尝试setSelection(0)但没有发生任何事情.请帮帮我,我该怎么办?
嗨,我正在开发一个应用程序,当用户想要重置他的密码时,要求OTP,我需要一个像附加图像中那样的文本...我想继续的是每个字母的单独文本,全部它们排列成水平方向的线性布局,有一些边距......最大长度为1,因此每个editText只能输入一个字母......这是一个正确的方法吗?有什么建议??