由网友(黎明、独徘徊)分享简介:可能重复: 机器人 - 出境申请code 我在android的初学者,我练一个项目,有一个2标签和1个退出按钮。但是,当我运行这个项目的android手机的退出按钮不工作,也不会退出的。我怎样才能退出按钮的工作?解决方案 下面使用main.xml中的文件< XML版本=1.0编码=UTF-8&GT?;&LT...![Win10如何一键关闭所有程序 一键秒关所有应用程序的方法](https://p.xsw88.cn/allimgs/daicuo/20230905/1438.png)
可能重复: 机器人 - 出境申请code
我在android的初学者,我练一个项目,有一个2标签和1个退出按钮。但是,当我运行这个项目的android手机的退出按钮不工作,也不会退出的。
我怎样才能退出按钮的工作?
解决方案下面使用main.xml中的文件
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
< TextView的Android的:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT机器人:ID =@ + ID / TXT1机器人:文本=TXT1/>
< TextView的Android的:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT机器人:ID =@ + ID / TXT2机器人:文本=TXT2/>
<按钮机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT机器人:ID =@ + ID / BTN1
机器人:文本=关闭程序/>
< / LinearLayout中>
和text.java文件小于
进口android.app.Activity;
进口android.os.Bundle;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.widget.Button;
公共类testprj延伸活动{
/ **第一次创建活动时调用。 * /
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
按钮BTN1 =(按钮)findViewById(R.id.btn1);
btn1.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
完();
System.exit(0);
}
});
}
}
![Win10如何一键关闭所有程序 一键秒关所有应用程序的方法](https://p.xsw88.cn/allimgs/daicuo/20230905/1438.png)
Possible Duplicate: android - exit application code
I'm a beginner in android, I'm practicing a Project that have a 2 labels and 1 exit button. But when I run this project in android phone the exit button is not working, it won't exit at all.
How can I make exit button work?
解决方案Below used main.xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/txt1" android:text="txt1" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/txt2" android:text="txt2"/>
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/btn1"
android:text="Close App" />
</LinearLayout>
and text.java file is below
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class testprj extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn1 = (Button) findViewById(R.id.btn1);
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
System.exit(0);
}
});
}
}
相关推荐
最新文章