鱼C论坛

 找回密码
 立即注册
查看: 2514|回复: 0

[学习笔记] android手机编程3.2.3 3.2.4

[复制链接]
发表于 2017-9-24 10:32:43 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
把activity_main.xml修改为:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:layout_width="match_parent"
  4.     android:layout_height="match_parent"
  5.     android:orientation="vertical"
  6.     >

  7.     <TextView
  8.         android:id="@+id/text"
  9.         android:layout_width="match_parent"
  10.         android:layout_height="wrap_content"
  11.         android:text="This is TextView"
  12.         android:gravity="center"
  13.         android:textSize="24sp"
  14.         android:textColor="#00ff00"
  15.         android:textStyle="bold"
  16.         />
  17.     <Button
  18.         android:id="@+id/button"
  19.         android:layout_width="wrap_content"
  20.         android:layout_height="wrap_content"
  21.         android:layout_gravity="center"
  22.         android:background="#00ff00"
  23.         android:layout_marginTop="50dp"
  24.         android:text="button"
  25.         />
  26.     <EditText
  27.         android:id="@+id/edit_text"
  28.         android:layout_width="match_parent"
  29.         android:layout_height="wrap_content"
  30.         android:hint="Type something here"
  31.         android:maxLines="2"
  32.         />
  33.     <ImageView
  34.         android:id="@+id/img_view"
  35.         android:layout_width="wrap_content"
  36.         android:layout_height="wrap_content"
  37.         android:src="@drawable/a"/>
  38.     <Button
  39.         android:id="@+id/button1"
  40.         android:layout_width="wrap_content"
  41.         android:layout_height="wrap_content"
  42.         android:layout_gravity="center"
  43.         android:background="#00f0f0"
  44.         android:layout_marginTop="10dp"
  45.         android:text="button1"
  46.         />
  47. </LinearLayout>
复制代码

先把两张准备好的图片复制到drawable目录下,如图:
asdasdasd.png
把mainactivity.java文件修改为:
  1. package com.example.xinwei.viewcontroller;

  2. import android.content.DialogInterface;
  3. import android.graphics.Color;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.widget.Button;
  8. import android.widget.EditText;
  9. import android.widget.ImageView;
  10. import android.widget.TextView;
  11. import android.widget.Toast;

  12. public class MainActivity extends AppCompatActivity implements View.OnClickListener{
  13.     private TextView myText;
  14.     private EditText editText;
  15.     private ImageView imageView;
  16.     private Button button1;
  17.     @Override
  18.     protected void onCreate(Bundle savedInstanceState) {
  19.         super.onCreate(savedInstanceState);
  20.         setContentView(R.layout.activity_main);
  21.         Button button = (Button)findViewById(R.id.button);
  22.         myText=(TextView)findViewById(R.id.text);
  23.         button.setOnClickListener(this);
  24.         editText = (EditText)findViewById(R.id.edit_text);
  25.         editText.setOnClickListener(this);
  26.         imageView = (ImageView)findViewById(R.id.img_view);
  27.         button1 = (Button)findViewById(R.id.button1);
  28.         button1.setOnClickListener(this);
  29.     }

  30.     @Override
  31.     public void onClick(View view) {
  32.         switch(view.getId()){
  33.             case R.id.button:
  34.                 myText.setTextColor(Color.parseColor("red"));
  35.                 break;
  36.             case R.id.edit_text:
  37.                 String inputText=editText.getText().toString().trim();
  38.                 Toast.makeText(this, inputText, Toast.LENGTH_SHORT).show();
  39.                 break;
  40.             case R.id.button1:
  41.                 imageView.setImageResource(R.drawable.logo);
  42.                 break;
  43.         }

  44.     }
  45. }
复制代码

文本编辑和图片显示这两个控件都是经常用的,都hen简单没什么可讲的,效果图图下:
jdfw.gif

评分

参与人数 2荣誉 +6 鱼币 +6 收起 理由
马太效应 + 1 + 1 支持楼主!
qingchen + 5 + 5 支持Android

查看全部评分

本帖被以下淘专辑推荐:

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-3-28 19:34

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表