Java – how do I create a GUI in Android instead of using XML?

I don't like managing XML and Java together. Can I use the Java language to create the same GUI?

Solution

Yes, you can

public class MyActivity extends Activity {
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);

         final Button button = new Button(this);
         button.setText("Press me!");
         setContentView(button);

         button.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 // Perform action on click
             }
         });
     }
 }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>