就是android 的后端,别人点击登陆,能在android studio 中显示出来,本人android小白 ,贴一下代码 纪念一下
前段按钮代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
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="com.example.button.MainActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/button_name"
android:id="@+id/button1"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:src="@android:drawable/sym_def_app_icon"
android:layout_below="@+id/button1" />
</RelativeLayout>
后端代码
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'宋体';font-size:9.6pt;"><span style="color:#cc7832;">package </span>com.example.button<span style="color:#cc7832;">;
</span><span style="color:#cc7832;">
</span><span style="color:#cc7832;">import </span>android.support.v7.app.AppCompatActivity<span style="color:#cc7832;">;
</span><span style="color:#cc7832;">import </span>android.os.Bundle<span style="color:#cc7832;">;
</span><span style="color:#cc7832;">import </span>android.view.View<span style="color:#cc7832;">;
</span><span style="color:#cc7832;">import </span>android.widget.Button<span style="color:#cc7832;">;
</span><span style="color:#cc7832;">
</span><span style="color:#cc7832;">public class </span>MainActivity <span style="color:#cc7832;">extends </span>AppCompatActivity {
<span style="color:#cc7832;">private </span>Button <span style="color:#9876aa;">loginButton</span><span style="color:#cc7832;">;
</span><span style="color:#cc7832;"> </span><span style="color:#bbb529;">@Override
</span><span style="color:#bbb529;"> </span><span style="color:#cc7832;">protected void </span><span style="color:#ffc66d;">onCreate</span>(Bundle savedInstanceState) {
<span style="color:#cc7832;">super</span>.onCreate(savedInstanceState)<span style="color:#cc7832;">;
</span><span style="color:#cc7832;"> </span>setContentView(R.layout.<span style="color:#9876aa;font-style:italic;">activity_main</span>)<span style="color:#cc7832;">;
</span><span style="color:#cc7832;"> </span><span style="color:#9876aa;">loginButton</span>= (Button) findViewById(R.id.<span style="color:#9876aa;font-style:italic;">button1</span>)<span style="color:#cc7832;">;
</span><span style="color:#cc7832;"> </span><span style="color:#9876aa;">loginButton</span>.setOnClickListener(<span style="color:#cc7832;">new </span>View.OnClickListener() {
<span style="color:#bbb529;">@Override
</span><span style="color:#bbb529;"> </span><span style="color:#cc7832;">public void </span><span style="color:#ffc66d;">onClick</span>(View view) {
System.<span style="color:#9876aa;font-style:italic;">out</span>.println(<span style="color:#6a8759;">"who am i"</span>)<span style="color:#cc7832;">;
</span><span style="color:#cc7832;"> </span>}
})<span style="color:#cc7832;">;
</span><span style="color:#cc7832;">
</span><span style="color:#cc7832;"> </span>}
}