您的位置:首页 > 其它

button tast

2016-09-08 20:00 134 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。本文链接:https://blog.csdn.net/qq_32342785/article/details/52474576

首先新建一个ButtonTest活动

ButtonActivity.java代码如下(主要执行的活动):

package com.example.activitytest;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.view.Window;import android.widget.Button;import android.widget.Toast;public class ButtonActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);//手动创建活动requestWindowFeature(Window.FEATURE_NO_TITLE);//隐藏标题栏setContentView(R.layout.button_layout);//手动创建活动
//实现一按下“叮咚”键就会执行跳出“小主”Button 叮咚= (Button) findViewById(R.id.button_1);叮咚.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Toast.makeText(ButtonActivity.this,"小主",Toast.LENGTH_SHORT).show();}});}}
button_layout.xml代码如下(配置一下按键的界面):
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical" android:layout_width="match_parent"    android:layout_height="match_parent"><Button        android:id="@+id/button_1"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="叮咚"/>
manifest.xml代码如下(注册活动):</LinearLayout>
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.activitytest"><application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:supportsRtl="true"        android:theme="@style/AppTheme"><activity android:name=".ButtonActivity"            android:label="Button"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity></application></manifest>









内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: