android开发学习——day8

android开发学习——day8,第1张

概述关于UI学习的总结EditText的练习MainActivity.java代码package test.example.com.ch02_button;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.TextView;public class MainActivit

  关于UI学习的总结

  EditText的练习

  MainActivity.java代码

package test.example.com.ch02_button;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);    }    int size=30;//字体大小,初值为30    public voID bigger(VIEw v){        TextVIEw txv;        txv= (TextVIEw) findVIEwByID(R.ID.txv);//强制类型转换        txv.setTextSize(++size);    }    public voID smaller(VIEw v){        if(size>30){            TextVIEw txv= (TextVIEw) findVIEwByID(R.ID.txv);            txv.setTextSize(--size);        }    }}

  电话簿UI练习

  1.利用属性设置布局

  2.按比例排布控件

  3.改变控件字体颜色以及背景颜色

  4.插入背景图片

  activity_main.xml代码

<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"xmlns:tools="http://schemas.androID.com/tools"    androID:ID="@+ID/activity_main"    androID:orIEntation="vertical"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:background="@mipmap/ic_launcher"    androID:paddingBottom="@dimen/activity_vertical_margin"    androID:paddingleft="@dimen/activity_horizontal_margin"    androID:paddingRight="@dimen/activity_horizontal_margin"    androID:paddingtop="@dimen/activity_vertical_margin"    tools:context="test.example.com.ch03_linearlayout.MainActivity">    <linearLayout        androID:orIEntation="horizontal"        androID:paddingtop="10dp"        androID:paddingBottom="10dp"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content">        <TextVIEw            androID:layout_wIDth="0dp"            androID:layout_height="wrap_content"            androID:layout_weight="1"            androID:textcolor="#ffa763ee"            androID:text="@string/firstname"            androID:textSize="25dp"/>        <EditText            androID:layout_wIDth="0dp"            androID:layout_height="wrap_content"            androID:inputType="textPersonname"            androID:text=""            androID:ems="10"            androID:ID="@+ID/editText"            androID:layout_weight="4"            androID:hint="输入姓氏"            androID:ellipsize="end"            androID:singleline="true" /><linearLayout        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:paddingtop="10dp"        androID:paddingBottom="10dp"        androID:orIEntation="horizontal">        <TextVIEw            androID:layout_wIDth="0dp"            androID:layout_height="wrap_content"            androID:layout_weight="1"            androID:textcolor="#ffa763ee"           androID:text="@string/lastname"            androID:textSize="25dp"/>        <EditText            androID:layout_wIDth="0dp"            androID:layout_height="wrap_content"            androID:inputType="textPersonname"            androID:text=""            androID:ems="10"            androID:ID="@+ID/editText1"            androID:layout_weight="4"            androID:hint="输入名字"            androID:ellipsize="end"            androID:singleline="true" /><linearLayout        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:paddingtop="10dp"        androID:paddingBottom="10dp"        androID:orIEntation="horizontal">        <TextVIEw            androID:layout_wIDth="0dp"            androID:layout_height="wrap_content"            androID:layout_weight="1"            androID:textcolor="#ffa763ee"            androID:text="@string/tel"            androID:textSize="25dp"/>        <EditText            androID:layout_wIDth="0dp"            androID:layout_height="wrap_content"            androID:inputType="phone"            androID:text=""            androID:ems="10"            androID:ID="@+ID/editText2"            androID:layout_weight="4"            androID:ellipsize="end"            androID:singleline="true"            androID:hint="(01)234567890" /><linearLayout        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:paddingtop="10dp"        androID:paddingBottom="10dp"        androID:orIEntation="horizontal">    <TextVIEw        androID:text="@string/psw"        androID:layout_wIDth="0dp"        androID:layout_height="wrap_content"        androID:layout_weight="1"        androID:textcolor="#ffa763ee"        androID:ID="@+ID/textVIEw"        androID:textSize="25dp"/>        <EditText            androID:layout_wIDth="0dp"            androID:layout_height="wrap_content"            androID:inputType="textPassword"            androID:ems="10"            androID:ID="@+ID/editText4"            androID:layout_weight="4"            androID:ellipsize="end"            androID:singleline="true" /><linearLayout    androID:orIEntation="vertical"    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:paddingtop="20dp"    androID:paddingBottom="20dp"    androID:paddingRight="30dp"    androID:paddingleft="30dp">    <button        androID:text="确定"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:textSize="20sp"        androID:textcolor="#00F"        androID:background="#80feff79"        androID:ID="@+ID/button"        androID:onClick="onClick" />    <TextVIEw        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:textSize="30dp"        androID:ID="@+ID/textVIEw3" />

  MainActivity.java代码

package test.example.com.ch03_linearlayout;import androID.support.v7.app.AppCompatActivity;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.Widget.EditText;import androID.Widget.TextVIEw;public class MainActivity extends AppCompatActivity {    EditText firstname,lastname,tel;    TextVIEw txv;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        firstname=(EditText)findVIEwByID(R.ID.editText);        lastname=(EditText)findVIEwByID(R.ID.editText1);        tel=(EditText)findVIEwByID(R.ID.editText2);        txv=(TextVIEw)findVIEwByID(R.ID.textVIEw3);    }    public voID onClick(VIEw v){        txv.setText(firstname.getText().toString()+lastname.getText().toString()+"的电话是"+tel.getText());    }}

  

  

  

  变色程序

  activity_main.xml代码

<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"xmlns:tools="http://schemas.androID.com/tools"    androID:ID="@+ID/activity_main"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:orIEntation="vertical"    androID:paddingBottom="@dimen/activity_vertical_margin"    androID:paddingleft="@dimen/activity_horizontal_margin"    androID:paddingRight="@dimen/activity_horizontal_margin"    androID:paddingtop="@dimen/activity_vertical_margin"    tools:context="test.example.com.chameleon_test.MainActivity">    <linearLayout        androID:ID="@+ID/colorblock"        androID:layout_weight="1"        androID:orIEntation="horizontal"        androID:layout_wIDth="match_parent"        androID:layout_height="0dp"        androID:paddingtop="20dp"        androID:paddingBottom="20dp"><linearLayout        androID:ID="@+ID/hello"        androID:orIEntation="horizontal"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:paddingtop="20dp"        androID:paddingBottom="20dp"><TextVIEw    androID:ID="@+ID/hhh"    androID:textSize="30dp"    androID:text="Hello World!"    androID:gravity="center"    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content" /><linearLayout        androID:orIEntation="horizontal"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:paddingtop="40dp"        androID:paddingBottom="20dp">        <TextVIEw            androID:ID="@+ID/txvR"            androID:text="@string/red"            androID:textSize="30dp"            androID:layout_wIDth="0dp"            androID:layout_height="wrap_content"            androID:layout_weight="1"/>        <TextVIEw            androID:ID="@+ID/txvG"            androID:text="@string/green"            androID:textSize="30dp"            androID:layout_wIDth="0dp"            androID:layout_height="wrap_content"            androID:layout_weight="1"/>        <TextVIEw            androID:ID="@+ID/txvB"            androID:text="@string/blue"            androID:textSize="30dp"            androID:layout_wIDth="0dp"            androID:layout_height="wrap_content"            androID:layout_weight="1"/><linearLayout        androID:orIEntation="horizontal"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:paddingtop="40dp"        androID:paddingBottom="20dp"        androID:paddingRight="30dp"        androID:paddingleft="30dp">    <button        androID:text="@string/change"        androID:textSize="20dp"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:ID="@+ID/button"        androID:onClick="changecolor" />

 

  MainActivity.java代码

package test.example.com.chameleon_test;import androID.graphics.color;import androID.support.v7.app.AppCompatActivity;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.Widget.TextVIEw;import java.util.Random;public class MainActivity extends AppCompatActivity {    TextVIEw red,green,blue,hh;    VIEw colorblock;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        red=(TextVIEw)findVIEwByID(R.ID.txvR);        green=(TextVIEw)findVIEwByID(R.ID.txvG);        blue=(TextVIEw)findVIEwByID(R.ID.txvB);        hh=(TextVIEw)findVIEwByID(R.ID.hhh);        colorblock=findVIEwByID(R.ID.colorblock);    }    public voID changecolor(VIEw v){        Random x=new Random();        int r=x.nextInt(256);        red.setText("红:"+r);        red.setTextcolor(color.rgb(r,0,0));        int g=x.nextInt(256);        green.setText("绿:"+g);        green.setTextcolor(color.rgb(0,g,0));        int b=x.nextInt(256);        blue.setText("蓝:"+b);        blue.setTextcolor(color.rgb(0,0,b));        colorblock.setBackgroundcolor(color.rgb(r,g,b));        hh.setTextcolor(color.rgb(r,g,b));    }}

  

  

  下划线的解决问题
  EIDtText和textvIEw中内容过长的话自动换行,使用androID:ellipsize与androID:singleine可以解决,使只有一行。
  EditText不支持marquee
  用法如下:
  在xml中
  androID:ellipsize = "end"    省略号在结尾
  androID:ellipsize = "start"   省略号在开头
  androID:ellipsize = "mIDdle"     省略号在中间
  androID:ellipsize = "marquee"  跑马灯
  androID:singleline = "true"

总结

以上是内存溢出为你收集整理的android开发学习——day8全部内容,希望文章能够帮你解决android开发学习——day8所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/999498.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-21
下一篇2022-05-21

发表评论

登录后才能评论

评论列表(0条)

    保存