Button控件
MainActivity
package com.example.hello;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivityextends AppCompatActivity{
private ButtonmbtnTextView;//声明
private ButtonmbtnButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mbtnTextView=findViewById(R.id.btn_textview);//找到这个id
mbtnTextView.setOnClickListener(new View.OnClickListener() {
@Override //点击事件
public void onClick(View view) {
//跳转到TextViewActivity页面
Intent intent=new Intent(MainActivity.this, TextViewActivity.class);
startActivity(intent);
}
});
mbtnButton=findViewById(R.id.btn_button);//找到这个id
mbtnButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//跳转到Button页面
Intent intent=new Intent(MainActivity.this,ButtonActivity.class);
startActivity(intent);
}
});
}
}
ButtonActivity
package com.example.hello;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class ButtonActivityextends AppCompatActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_button);
}
}
TextviewActivity
package com.example.hello;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Paint;
import android.os.Bundle;
import android.widget.TextView;
public class TextViewActivityextends AppCompatActivity{
private TextViewmTv4;//中划线
private TextViewmTv7;//跑马灯
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text_view);
mTv4=findViewById(R.id.tv_4);
mTv4.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
//去除锯齿mTv4.getPaint().setAntiAlias(true);
mTv7=findViewById(R.id.tv_7);
mTv7.setSelected(true);
}
}
activity_Button.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp">
<Button
android:id="@+id/btn_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="按钮1"
android:textSize="40sp"
android:textColor="#FF8C00"
android:background="#ffffcc"/>
<Button //圆角
android:id="@+id/btn_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="按钮2"
android:textSize="30dp"
android:textColor="#FF8C00"
android:background="@drawable/bg_btn2"
android:layout_below="@id/btn_1"
android:layout_marginTop="10dp"/>
<Button
android:id="@+id/btn_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="按钮3"
android:textColor="#FF8C00"
android:background="@drawable/bg_btn3"
android:layout_below="@id/btn_2"
android:textSize="40dp"
android:layout_marginTop="10dp"/>
<Button
android:id="@+id/btn_4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="按钮4"
android:textSize="40sp"
android:textColor="#FF8C00"
android:background="@drawable/bg_btn4"
android:layout_below="@id/btn_3"/>
</RelativeLayout>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:id="@+id/btn_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"/>
<Button
android:id="@+id/btn_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"/>
</LinearLayout>
activity_text.xml
<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_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第一个TextView哦!"
android:textColor="#FF7F24"
android:textSize="30sp"
android:padding="20dp"/>
<TextView
android:id="@+id/tv_2"
android:layout_width="210dp"
android:layout_height="wrap_content"
android:text="第一个TextView哦!"
android:maxLines="1"
android:ellipsize="end"
android:textColor="#FF7F24"
android:textSize="30sp"
android:padding="20dp"
android:layout_marginTop="10dp"/>
<TextView
android:id="@+id/tv_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="50sp"
android:padding="10dp"
android:text="筛选"/>
<TextView
android:id="@+id/tv_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第一个TextView哦!"
android:textColor="#FF7F24"
android:textSize="30sp"
android:padding="20dp"/>
<TextView
android:id="@+id/tv_7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是一号跑马灯我是二号跑马灯我是三号跑马灯我是四号跑马灯"
android:textSize="50dp"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"/>
</LinearLayout>
AndriodManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hello">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".ButtonActivity"></activity>
<activity android:name=".TextViewActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
bg_btn2
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#FFC125"/>
<corners
android:radius="10dp"/>
</shape>
bg_btn3
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="#6633ff"/>
<corners
android:radius="10dp"/>
</shape>
bg_btn4
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<solid android:color="#763A12"/>
<corners android:radius="5dp"/>
</shape>
</item>
<item android:state_pressed="false">
<shape>
<solid android:color="#EFBB98"/>
<corners android:radius="5dp"/>
</shape>
</item>
</selector>