Skip to content

Create a Android custom view #3251

@jusierra

Description

@jusierra

I try to implement a custom view in a Android app. In the following code, my Toast is called but then I would like to apply a layout to my view.

public class YouTubeView extends View {

            public YouTubeView(Context context, Context activity) {
                  super(context);
                  Toast.makeText(context, "Well done.", Toast.LENGTH_LONG).show();
            }
}

Can I extend my class from something else to be able to add LinearLayout or whatever, set height and width and put some elements inside ? Can I use a xml layout that I could inflate ? The doc is not so accurate ...

I hope to be clear in my question.
Thank you very much for your answers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions