本文介绍了如何设置动作条标识为文本(TextView的)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图使动作条标志,或向上按钮,文本,而不是图像。 actionbar.setLogo(); 只接受一个绘制资源。充气带布局的的TextView 并没有这样的伎俩。

I've been trying to make the ActionBar logo, or the Up button, a text instead of an image. actionbar.setLogo(); accepts only a drawable resource. Inflating a layout with a TextView didn't do the trick.

基本上,我想要做到的是这样的:

Basically, what I'm trying to accomplish is this:

第一个是从安卓4.2新DeskClock应用程序,第二个是从联系人应用程序。我检查了code在GitHub上,但我无法找到任何东西。

The first one is from the new DeskClock app from Android 4.2 and the second is from the Contacts app. I checked the code in GitHub but I couldn't find anything.

推荐答案

下面是@ CommonsWare的选项#1的实现,完美的作品。

Here is an implementation of @CommonsWare's option #1, works perfectly.

TextView upTextView = (TextView) getLayoutInflater().inflate(
        R.layout.up_text, null);
upTextView.setText("CITIES");
upTextView.measure(0, 0);
upTextView.layout(0, 0, upTextView.getMeasuredWidth(),
        upTextView.getMeasuredHeight());
Bitmap bitmap = Bitmap.createBitmap(upTextView.getMeasuredWidth(),
        upTextView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
upTextView.draw(canvas);
BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);

R.layout.up_text

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingLeft="4dp"
    android:paddingRight="4dp"
    android:textColor="#f00"
    android:textSize="20sp"
    android:textStyle="bold" />

这篇关于如何设置动作条标识为文本(TextView的)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 20:01