首页 > 编程语言 >Android Studio第一个程序的开发

Android Studio第一个程序的开发

时间:2023-02-22 20:55:20浏览次数:35  
标签:layout tv text 程序 id Studio Android android TextView

1:首先创建一个device,创建成功后运行,就会显示text的内容,为了修饰,打开code,编写代码修改手机app,遇到一个问题就是在xml编写

android:background="#f00">无效,在TextView中修改text和textSize都是有效的,运行后在虚拟手机里面可以看到我制作的app叫做 my application
在project的目录里面,app存放项目的代码,资源,是工作的核心,第三个gradle是构建器。
选择project,通过build的make project一下生成app中的build目录


2:控件TextView:,找到active.project按住ctrl加鼠标左键可以打开进行text view的书写,
LinearLayout是容器,TextView需要放到容器里面,layout_width="match_parent",代表是容器的宽度,layout_width="wrap_content"代表自动分配宽度,


layout_width="200dp"
android:id="@+id/tv_one"中id是为了给Java代码获取TextView
正式开发中text是写在values的string_xml中的,
今天的问题就是
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:id="@+id/tv_one"
android:text="@string/tv_one"
android:textColor="@color/black"
android:textStyle="bold"
android:textSize="30sp"
android:background="#FFFF0000"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="200dp"




</LinearLayout>
无法连接的虚拟手机

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv_one=findViewById(R.id.tv_one);//获取TextView
tv_one.setText("Leo");//也是用来设置TextView的中的text属性,但是运行的话Java代码设置的会把xml的代码覆盖






}
}



标签:layout,tv,text,程序,id,Studio,Android,android,TextView
From: https://www.cnblogs.com/fengjiale/p/17145837.html

相关文章