Android 斜体编辑文本剪切第一个字母
我有一个简单的表格,有两个斜体字体的编辑文本,但有些字母(p和j)放在第一个位置时在左边被“剪切”。我试着用可拉伸的衬垫来固定它,但它不起作用。在我的例子中,在第一个字母前插入一个空格不是一个解决方案,至少不是最好的,因为第二个表单字段是密码字段,因此由于空格字符,将自动向用户显示一个点。EditText具有以下代码:Android 斜体编辑文本剪切第一个字母,android,android-layout,android-edittext,android-fonts,Android,Android Layout,Android Edittext,Android Fonts,我有一个简单的表格,有两个斜体字体的编辑文本,但有些字母(p和j)放在第一个位置时在左边被“剪切”。我试着用可拉伸的衬垫来固定它,但它不起作用。在我的例子中,在第一个字母前插入一个空格不是一个解决方案,至少不是最好的,因为第二个表单字段是密码字段,因此由于空格字符,将自动向用户显示一个点。EditText具有以下代码: <EditText android:id="@+id/edit_txt_login" android:layout_width="match
<EditText
android:id="@+id/edit_txt_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rectangle_white"
android:drawableLeft="@drawable/ic_mail"
android:drawablePadding="10dp"
android:ems="10"
android:hint="@string/login_email_placeholder"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:padding="10dp"
android:textColor="@color/black"
android:textCursorDrawable="@null"
android:textColorHint="@color/color_form_login_text"
android:textSize="17sp" >
错误图像:
解决方案是什么?尝试在左侧添加填充。试试这个:
<EditText
android:id="@+id/edit_txt_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rectangle_white"
android:drawableLeft="@drawable/ic_mail"
android:drawablePadding="10dp"
android:ems="10"
android:hint="@string/login_email_placeholder"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:padding="10dp"
android:paddingLeft="45dp"
android:textColor="@color/black"
android:textCursorDrawable="@null"
android:textColorHint="@color/color_form_login_text"
android:textSize="17sp" >
尝试给予
android:paddingLeft
多于10dp
或者将android:drawablePadding减少到4或5dp,这就是解决方案。我已经用自定义字体创建了自定义编辑文本
package com.example.customcontrols;
import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.EditText;
public class MyEditTextItalic extends EditText {
/*
* Caches typefaces based on their file path and name, so that they don't
* have to be created every time when they are referenced.
*/
private static Typeface mTypeface;
public MyEditTextItalic(Context context) {
super(context);
setTypeface(context);
}
public MyEditTextItalic(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setTypeface(context);
}
public MyEditTextItalic(Context context, AttributeSet attrs) {
super(context, attrs);
setTypeface(context);
}
// intercept Typeface change and set it with our custom font
public void setTypeface(Context context) {
if (mTypeface == null) {
mTypeface = Typeface.createFromAsset(context.getAssets(),
"fonts/HelveticaNeue-Bold.otf");
}
super.setTypeface(mTypeface,Typeface.ITALIC);
}
}
不创建字体斜体非常重要,因为它不能正确显示,在设置字体时使用斜体,请使用super.setTypeface(mTypeface,typeface.italic)
in.xml
<com.example.customcontrols.MyEditTextItalic
android:id="@+id/edit_txt_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="@drawable/rectangle_white"
android:drawableLeft="@drawable/ic_key"
android:drawablePadding="10dp"
android:ems="10"
android:hint="@string/login_password_placeholder"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:padding="10dp"
android:textColor="@color/black"
android:textCursorDrawable="@null"
android:textStyle="bold|italic"
android:textColorHint="@color/color_form_login_text"
android:textSize="17sp" />
这对我很有效,将自定义的宽度设置为xml布局:
android:width="130dp" //Define a value larger than your text.
通过给
TextView
一个文本阴影,可以强制它在其边界之外绘制。如果将“阴影颜色”设置为“透明”,那么就有了解决方案!将这些添加到您的文本视图中
:
android:shadowColor="#00FFFFFF"
android:shadowDx="48"
android:shadowDy="0"
android:shadowRadius="1"
在我的测试中,我发现#00000000不起作用,48的大小足以显示所有剪辑的文本,阴影和阴影半径是必要的。@nomada你能看到我下面的答案吗?移动ems不起作用
android:shadowColor="#00FFFFFF"
android:shadowDx="48"
android:shadowDy="0"
android:shadowRadius="1"