android从xml创建控件(按钮)或直接创建控件

android从xml创建控件

根据xml创建view (res/layout 这个文件夹中的play_cartoon_exit.xml)
View viewxml=getLayoutInflater().inflate(R.layout.play_cartoon_exit,null);

xml中有个id为button的Button
private Button  button=(Button)findViewById(R.id.button)



直接创建控件
直接创建view
继承View的自定义view
public class ComicLivePlayerView extends View{
}

final ComicLivePlayerView view = new ComicLivePlayerView(this);

直接创建button
Button btnJump = new Button(this);

你可能感兴趣的:(xml,android)