简体   繁体   中英

How to render custom view in designer?

I have created a simple custom TextView . The layout designer however, won't let me preview those custom TextViews , only MockView -Blocks are being rendered.

public class MainTextView : TextView
{
        public Typeface typeface;

        public MainTextView (Context context) : base(context, null)
        {
            InitializeView(context);
        }
     ...
}

Is how my class goes. I would like to preview my custom TextViews , but how can I do that?

If you are in the layout file, you can use:

<(insert your namespace for MainTextView here).MainTextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="Hello world" />

That should work, you just have to put the namespace that your textview is a part of.

I would also like to note that I've had issues with Visual Studio failing to render my views no matter what I do, so in those situations there's not much you can do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM