安卓小工程

本周get一个新技能,做一个简单的安卓界面。
简单操作一哈!!!

1、打开eslipse->file->New->Android Application Project

随后就会弹出界面,填写安卓工程的名称。

!!!注意:Pakage Name 不可以出现中文哦

在这里插入图片描述

2、点击Next

在这里插入图片描述

3、点击Next,根据自己的喜好做以下设置。(看看英文就能了解是啥意思,自己设置哦)

在这里插入图片描述

4、全选默认就好,点击Next

在这里插入图片描述

5、依然选择默认,Finish

在这里插入图片描述

6、接下来就是愉快的代码时间

MainActivity.java

package com.example.android;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >
    
<RelativeLayout 
    
    
    android:layout_width="match_parent"	
    android:layout_height="45dp"
    android:background="#D4B00B" 	//选择背景颜色
    
    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello Wrold" 
        android:textSize="18sp"
        android:textColor="#ffffff"
        android:layout_centerVertical="true"
        android:layout_marginLeft="30dp"
        />

    
 
    </RelativeLayout>

    
    <RelativeLayout 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="50dp"
     
        >
        <Button 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Welcome"
            android:textSize="25sp"
         
            android:textColor="#f0f0f0"
         
            />
        
    </RelativeLayout>
     

</RelativeLayout>


7、选择“Android”工程右键->Run As -> Android Application

连上手机试试效果

在这里插入图片描述

你成功了吗?
快去试试吧

发布了83 篇原创文章 · 获赞 55 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_45380951/article/details/103627778
今日推荐