相关疑难解决方法(0)

为什么我的Button文本强制在Lollipop上的所有大写?

在我的应用程序"Tide Now WA"中,我最近使用新的Nexus 9平板电脑(Lollipop - API 21)测试了兼容性.

它会写一些按钮文字.此应用程序使用Android 2.3和Android 4.0正确编写文本.即混合资本和小写字母.

当我的Nexus 9上运行相同的应用程序时,文本中的所有字母都大写.

FWIW我的清单包含以下声明:

uses-sdk android:minSdkVersion="10" android:targetSdkVersion="14"

我可以在我的代码中修复此问题,还是操作系统中的错误感谢

android android-button android-styles android-5.0-lollipop

418
推荐指数
15
解决办法
18万
查看次数

如何布局文本以在图像周围流动

你能否告诉我是否有办法在图像周围布置文字?像这样:

------  text text text
|    |  text text text
-----   text text text
text text text text
text text text text
Run Code Online (Sandbox Code Playgroud)

我从android开发者那里得到了关于这个问题的回复.但我不确定通过自己的TextView版本意味着什么?感谢任何提示.

2010年2月8日星期一晚上11:05,Romain Guy写道:

嗨,

仅使用提供的小部件和布局无法做到这一点.您可以编写自己的TextView版本来执行此操作,这应该不难.

android android-layout

68
推荐指数
4
解决办法
3万
查看次数

TextView具有lineSpacing时的ImageSpan.ALIGN_BASELINE

我想将我ImageSpan的文本基线对齐,但我还需要在行之间添加一些间距.
问题是,当我添加行间距时,ImageSpan它不会与文本的基线对齐,而是与文本的基线对齐baseline+lineSpacing,因此它看起来比它应该低.

这有解决方法吗?

编辑:进一步说明:

  1. 没有 它的样子lineSpacing(箭头是ImageSpan).它与基线正确对齐.
    在此输入图像描述

  2. 如果我添加,它看起来如何 android:lineSpacingMulitiplier="1.2"
    在此输入图像描述

编辑2代码:
XML:

<com.kushtrim.example.views.CustomTypefaceTextView
    android:id="@+id/descId"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:lines="3"
    android:gravity="center_vertical"
    android:layout_marginLeft="@dimen/_45"
    android:layout_marginTop="@dimen/_6"
    android:layout_marginBottom="@dimen/_20"
    app:font_type="merriweather_regular"
    android:textSize="@dimen/f40"
    android:lineSpacingMultiplier="1.2"
    android:textColor="@color/black"
    android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit."
    android:ellipsize="end" />
Run Code Online (Sandbox Code Playgroud)

其他相关方法:

    private Spannable getContentText(ContactRaport contactRaport) {
    DateTime dateTime = new DateTime(contactRaport.contactDate);

    String datePart = dateTime.getDayOfMonth() + " " + dateTime.monthOfYear().getAsShortText(new Locale("nl")) + "; ";
    String completeText = datePart + contactRaport.note;

    Typeface font1 = Typeface.createFromAsset(context.getAssets(), "MyFont1.ttf"); …
Run Code Online (Sandbox Code Playgroud)

android textview imagespan

8
推荐指数
1
解决办法
1785
查看次数

如何从 ImageSpan 内的 xml 矢量设置 Drawable

如何Drawable从 xml 向量中设置ImageSpan?我使用下面这两种方法。但我的图标没有显示。当我使用可绘制资源图标中的 png 时,会显示出来。任何想法?

private void setupEmptyListInfoBox() {
        Drawable icon = loadVectorFromResources(getActivity(), R.drawable.ic_add_circle_24dp);
        ImageSpan is = new ImageSpan(icon, DynamicDrawableSpan.ALIGN_BASELINE);
        String info = getString(R.string.empty_weight_list_info);
        int iconPosition = info.indexOf("|");

        SpannableString text = new SpannableString(info);
        text.setSpan(is, iconPosition, iconPosition + 1, 0);

        mEmptyListInfo.setText(text);
    }

public static Drawable loadVectorFromResources(Context context, int resId) {
    Drawable drawable;
    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        drawable = VectorDrawableCompat.create(context.getResources(), resId, context.getTheme());
    } else {
        drawable = context.getResources().getDrawable(resId, context.getTheme());
    }
    return drawable;
}
Run Code Online (Sandbox Code Playgroud)

android drawable android-drawable android-vectordrawable

7
推荐指数
1
解决办法
1779
查看次数

错误(或提示)文本的Android TextInputLayout图标

我正在使用TextInputLayoutHelper小部件,以便遵循浮动标签输入的材料准则。当前看起来像这样:

带有错误消息的浮动输入标签

我的密码

在活动onCreate功能中,我具有:

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    val passwordInputLayout = this.findViewById<TextInputLayoutHelper>(R.id.input_layout_password)
    passwordInputLayout.error = "8+ characters and at least one uppercase letter, a number, and a special character (\$, #, !)"
    passwordInputLayout.isErrorEnabled = true
}
Run Code Online (Sandbox Code Playgroud)

和我的小部件xml看起来像...

<TextInputLayout
    android:id="@+id/input_layout_password"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/EditTextTheme"
    app:errorEnabled="true"
    app:errorTextAppearance="@style/ErrorAppearance"
    app:passwordToggleDrawable="@drawable/asl_password_visibility"
    app:passwordToggleEnabled="true"
    app:passwordToggleTint="?colorControlNormal">

    <EditText
        android:id="@+id/password_edit_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="@string/set_a_password"
        android:inputType="textPassword"
        android:singleLine="true" />

</TextInputLayout>
Run Code Online (Sandbox Code Playgroud)

我想做的事

我想在错误文本的右侧的错误/提示文本(感叹号三角形)中放置一个图标。

模拟带有错误图标的输入

我的尝试

尝试1

我发现使用了一个实现setError(text, drawable)但我正在使用的Kotlin实现setError不可用。

所以我尝试了:

val warningIcon = …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-drawable

6
推荐指数
1
解决办法
3701
查看次数

Android-ImageSpan-如何居中对齐文本末尾的图像

我在xml布局中具有以下内容:

在此处输入图片说明

注意六角形#4如何不在文本的中心对齐。我该怎么做:这是到目前为止我尝试过的事情:

为了真正获得其中带有#的视图,我给视图添加一个如下所示的视图:

//my_hexagon_button.xml:

     <?xml version="1.0" encoding="utf-8"?>
       <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                     xmlns:tools="http://schemas.android.com/tools"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:orientation="vertical"
                     android:padding="0dp"
                     tools:ignore="MissingPrefix">


           <Button
               android:id="@+id/tv_icon"
               fontPath="proxima_nova_semi_bold.otf"
               android:layout_width="16dp"
               android:layout_height="17.5dp"
               android:layout_marginBottom="5dp"
               android:layout_marginLeft="10dp"
               android:alpha=".25"
               android:background="@drawable/hexagon"
               android:clickable="true"
               android:contentDescription="@string/content_description"
               android:focusable="false"
               android:padding="0dp"
               android:text="4"
               android:textColor="@color/white"
               android:textSize="8dp"
               />

       </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

扩大视图后,我获取其图形缓存的副本,并在ImageSpan中使用它。这是我如何获取图形缓存的副本:

public Bitmap getIconBitmap() {
               LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
               LinearLayout myRoot = new LinearLayout(getActivity());

               // inflate and measure the button then grab its image from the view cache
               ViewGroup parent = (ViewGroup) inflater.inflate(R.layout.my_hexagon_button, myRoot);
               TextView tv = (TextView) parent.findViewById(R.id.tv_icon);

               parent.setDrawingCacheEnabled(true);
               parent.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
                       View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
               parent.layout(0, 0, …
Run Code Online (Sandbox Code Playgroud)

android spannablestring

1
推荐指数
3
解决办法
3577
查看次数