Android的编程方式中风 [英] Android Programatically Stroke

查看:199
本文介绍了Android的编程方式中风的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要吸取我的文字的Andr​​oid黑色中风。

I want to draw a black stroke on my text in Android.

我已经看到了这个例子:
<一href=\"http://stackoverflow.com/questions/1723846/how-do-you-draw-text-with-a-border-on-a-mapview-in-android\">How你对Android中一个图形页面边框绘制文本?

I have seen this example: How do you draw text with a border on a MapView in Android?

在哪里解决方案覆盖的onDraw()创建的笔触。

Where the solution overrides onDraw() to create the stroke.

问题是,我仍然在Android的相对开始了,我不知道如何过渡到使用该解决方案。

The problem is, I'm still relatively starting out in Android, and I have no idea how to transition to using that solution.

在我的onCreate我设置文本​​字体(它的自定义):

In my onCreate I set the text typeface (it's custom):

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeatures();

    // Set content view and component listeners
    setContentView(R.layout.meme_maker);
    setListeners();

    context = this;

    Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Impact.ttf");
    TextView mmt = (TextView) findViewById(R.id.meme_maker_title);
    TextView ttc = (TextView) findViewById(R.id.top_text_canvas);
    TextView tbc = (TextView) findViewById(R.id.bottom_text_canvas);

    ttc.setTypeface(tf);
    tbc.setTypeface(tf);
    mmt.setTypeface(tf);
}

和我有一个onClickListener,我改变的TextView的文本内容,根据用户写他/她想要在TEXTENTRY文本,点击按钮之后。

And I have an onClickListener where I change the text content of the TextView, based on the user writing the text he/she wants in a TextEntry and clicking a button afterwards.

ImageView ii = (ImageView) findViewById(R.id.insert_image);
    ii.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EditText tt = (EditText) findViewById(R.id.top_text_text);
            EditText bt = (EditText) findViewById(R.id.bottom_text_text);

            TextView ttc = (TextView) findViewById(R.id.top_text_canvas);
            TextView btc = (TextView) findViewById(R.id.bottom_text_canvas);

            ttc.setText(tt.getText().toString().toUpperCase());
            btc.setText(bt.getText().toString().toUpperCase());
        }
    });

这是pretty简单为止。我的问题是:如何插入文本的行程?哪里?我需要创建一个画布和颜料对象?

It's pretty straightforward so far. My question is: how to insert the stroke of the text? Where? Do I need to create a Canvas and Paint objects?

感谢您

推荐答案

要获得在一个TextView呈现的文本阴影的最简单方法是在的这个答案。这需要很少的工作,听起来就像是会在你的情况下正常工作。

The simplest way to get a shadow for text rendered in a TextView is to set up a style as described in this answer. That requires very little work and sounds like it will work fine in your situation.

使用您链接到涉及延长现有的View类,覆盖的onDraw(),并传递到的onDraw在画布上用Canvas.drawText()技术()将自己呈现文本。这可正是你在某些情况下需要的东西,但听起来像矫枉过正你现在的情况。如果你想看看它进一步,关于这一主题的Andr​​oid的开发者指南是一个很好看的。

Using the technique you link to involves extending an existing View class, overriding onDraw(), and using Canvas.drawText() on the canvas passed to onDraw() to render the text yourself. That can be exactly what you need in some situations, but sounds like overkill for your current situation. If you want to look into it further, the Android dev guide on the subject is a good read.

这篇关于Android的编程方式中风的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆