码迷,mamicode.com
首页 > 移动开发 > 详细

创建一个Android项目

时间:2018-11-15 01:28:37      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:新建   version   string   oid   over   odi   jce   xmlns   this   

创建一个Android项目

1.点击File-New Project

技术分享图片

2.Next-选择Phone 这里的SDK选择Android7.1.1

技术分享图片

3.Add no activity

技术分享图片

4.错误解决

我们在建立完后经常会报如下的错误:

技术分享图片

这里首先你需要查看你的SDK的版本,首先进行更改版本,我这里更改如下:

技术分享图片

注释掉junit:

技术分享图片

更改:

技术分享图片

allprojects {
    repositories {
//        jcenter()
        maven { url 'http://repo1.maven.org/maven2' }
    }
}

然后重新引入下相关的gradle即可

5.建立好的文件结构如下:

技术分享图片

6.在com.example.activity 中创建新的类FirstActivity

技术分享图片

技术分享图片

Generate Layout File勾选的话会默认创一个默认的布局,launcher Activity只的是把当前的类当做主活动

7.在res中新建一个Directory 命名layout 再在该目录下建一个layout_resource_file,名为first_layout

技术分享图片

技术分享图片

8.修改first_layout .xml文件,加一个Button

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <Button
        android:id="@+id/button_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button 1"
        />

</LinearLayout>

然后在主类窗口中加载这个按钮:

package com.example.activitytest;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class FirstActivity extends AppCompatActivity {

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

修改AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.activitytest">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".FirstActivity"
            android:label="this is first"
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>

</manifest>

9.启动程序,可以看到如下的画面,说明你已经创建了一个Android项目了:

技术分享图片

创建一个Android项目

标签:新建   version   string   oid   over   odi   jce   xmlns   this   

原文地址:https://www.cnblogs.com/charlypage/p/9961141.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!