ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

app简单控件了解——文本框

2022-07-02 14:02:42  阅读:231  来源: 互联网

标签:控件 code tv app 文本框 import android hello TextView


示例:

<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_hello"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="你好,世界"
        android:textSize="50dp"
        android:textColor="#00ff00"
        android:background="@color/black"/>

</LinearLayout>

 

 



<TextView
android:id="@+id/tv_hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="你好,世界" -------设置文本内容
android:textSize="50dp" -----设置字体大小
android:textColor="#00ff00" --------设置字体颜色
android:background="@color/black"/> ------设置文本框背景颜色

 

 

 

 

 

 

 

 

 

====================================================================

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

TextView tv_hello = findViewById(R.id.tv_hello);
tv_hello.setText("你好,世界"); // 设置tv_hello的文字内容

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

====================================================================================

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

<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_hello"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello"
        android:textSize="50dp"
        android:textColor="#00ff00"
        android:background="@color/black"/>

</LinearLayout>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

------------------------------------------------------------------------------------------------------------

 

 

 

package com.example.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity
{

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


        // 获取名叫tv_hello的文本视图
        TextView tv_hello = findViewById(R.id.tv_hello);


//        tv_hello.setText("你好,世界"); // 设置tv_hello的文字内容


        tv_hello.setText(R.string.hello); // 设置tv_hello的文字资源
    }



}

 

 

 

 

 

 

 

 

 

 

 

=======================================================================================

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

package com.example.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity
{

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


        // 获取名叫tv_hello的文本视图
        TextView tv_hello = findViewById(R.id.tv_hello);


//        tv_hello.setText("你好,世界"); // 设置tv_hello的文字内容


        tv_hello.setText(R.string.hello); // 设置tv_hello的文字资源

        tv_hello.setTextSize(100);
    }



}

 

 

 

 

 

 

 

 

 

 

 

 

 

=============================================================================

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

<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_hello"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello"
        android:textSize="50dp"
        android:textColor="@color/as"
        android:background="@color/black"/>

</LinearLayout>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

---------------------------------------------------------------------------------------------------------------------------------

 

 

 

 

 

package com.example.myapplication;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity
{

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


        // 获取名叫tv_hello的文本视图
        TextView tv_hello = findViewById(R.id.tv_hello);


//        tv_hello.setText("你好,世界"); // 设置tv_hello的文字内容


        tv_hello.setText(R.string.hello); // 设置tv_hello的文字资源

        tv_hello.setTextSize(100);

        tv_hello.setTextColor(Color.LTGRAY);  //设置字体颜色

        tv_hello.setBackgroundColor(Color.GREEN); // 在代码中定义的色值  //设置背景颜色


    }



}

 

 

 

 

 

 

 

 

 

===========================================================================

 

 

 

 

PS:

 

package com.example.chapter03;

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

import androidx.appcompat.app.AppCompatActivity;

public class TextColorActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_text_color);
        // 从布局文件中获取名叫tv_code_system的文本视图
        TextView tv_code_system = findViewById(R.id.tv_code_system);
        
        
        // 将tv_code_system的文字颜色设置系统自带的绿色
        tv_code_system.setTextColor(Color.GREEN);
        
        
        // 从布局文件中获取名叫tv_code_six的文本视图
        TextView tv_code_six = findViewById(R.id.tv_code_six);
        
        
        // 将tv_code_six的文字颜色设置为透明的绿色,透明就是看不到
        tv_code_six.setTextColor(0x00ff00);
        
        
        // 从布局文件中获取名叫tv_code_eight的文本视图
        TextView tv_code_eight = findViewById(R.id.tv_code_eight);
        
        
        // 将tv_code_eight的文字颜色设置为不透明的绿色,即正常的绿色
        tv_code_eight.setTextColor(0xff00ff00);
        
        
        // 从布局文件中获取名叫tv_code_background的文本视图
        TextView tv_code_background = findViewById(R.id.tv_code_background);
        
        
        // 将tv_code_background的背景颜色设置为绿色
        tv_code_background.setBackgroundColor(Color.GREEN); // 在代码中定义的色值
        tv_code_background.setBackgroundResource(R.color.green); // 颜色来源于资源文件
    }
}

 

 

标签:控件,code,tv,app,文本框,import,android,hello,TextView
来源: https://www.cnblogs.com/xiaobaibailongma/p/16437457.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有