[推荐]图文详细,创建第一个AndroidStudio项目

AndroidStudio_2016.10.19最新版本第一个android项目的创建,希望可以帮助到开始学习android的小伙伴们.
摘要由CSDN通过智能技术生成

[1]我们点击第一个,创建一个新的AndroidStudio项目:

选项1 : 创建一个Android Studio项目。
选项2 : 打开一个Android Studio项目。
选项3 : 从版本控制系统中导入代码。支持 CVS 、 SVN 、 Git 、 Mercurial , 甚至GitHub。
选项4: 导入非Android Studio项目。比如纯生的 Eclipse Android项目, IDEA Android项目。如果你的Eclipse 项目使用官方建议导出(即使用 Generate Gradle build files 的方式导出),建议使用 选项2 导入。
选项5 : 导入官方样例


[2]确定项目名字/包名和项目路径然后点击Next

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面我会为您提供利用Android Studio设计一个记事本的详细图文教程,敬请参考。 1.创建项目 打开Android Studio创建一个新项目。选择“Empty Activity”作为您的模板。然后选择一个项目名称和位置,然后单击“Finish”按钮。 2.设计布局 设计记事本的布局。您需要添加一个EditText控件和一些按钮,例如保存,打开和新建。在XML文件中添加以下代码: ``` <EditText android:id="@+id/editText" android:layout_width="match_parent" android:layout_height="match_parent" android:inputType="textMultiLine" android:gravity="top|left" android:padding="10dp"/> <Button android:id="@+id/newFile" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New"/> <Button android:id="@+id/openFile" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Open"/> <Button android:id="@+id/saveFile" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Save"/> ``` 3.处理按钮事件 接下来,您需要处理按钮的单击事件。在MainActivity.java文件中添加以下代码: ``` public class MainActivity extends AppCompatActivity { private EditText editText; private Button newFileButton, openFileButton, saveFileButton; private String fileName = ""; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); editText = (EditText) findViewById(R.id.editText); newFileButton = (Button) findViewById(R.id.newFile); openFileButton = (Button) findViewById(R.id.openFile); saveFileButton = (Button) findViewById(R.id.saveFile); newFileButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editText.setText(""); fileName = ""; } }); openFileButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("text/plain"); startActivityForResult(intent, 1); } }); saveFileButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (fileName.equals("")) { Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TITLE, "Untitled.txt"); startActivityForResult(intent, 2); } else { saveFile(fileName); } } }); } private void saveFile(String fileName) { try { FileOutputStream fos = openFileOutput(fileName, MODE_PRIVATE); fos.write(editText.getText().toString().getBytes()); fos.close(); Toast.makeText(this, "File saved.", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); } } @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { switch (requestCode) { case 1: try { Uri uri = data.getData(); InputStream is = getContentResolver().openInputStream(uri); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder stringBuilder = new StringBuilder(); String line = ""; while ((line = reader.readLine()) != null) { stringBuilder.append(line); } is.close(); editText.setText(stringBuilder.toString()); fileName = uri.getLastPathSegment(); Toast.makeText(this, "File opened.", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); } break; case 2: Uri uri = data.getData(); fileName = uri.getLastPathSegment(); saveFile(fileName); break; } } } } ``` 4.运行应用程序 现在,您已经成功创建了一个简单的记事本应用程序。您可以运行该应用程序并使用它来编辑,保存和打开文本文件。 总结 以上就是利用Android Studio设计一个记事本的详细图文教程,希望对您有所帮助。如果您有任何疑问,请随时联系我。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值