目錄html
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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" tools:context=".MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!20175204 20175205 20175206" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout>
AndroidManifest.xml
,添加一個activity活動<activity android:name=".ThirdActivity"> </activity>
ThirdActivity.java
文件third_activity.xml
文件MainActivity.java
package com.example.administrator.myapplication; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.TextView; public class MainActivity extends Activity implements OnTouchListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView tv = (TextView) findViewById(R.id.textView1); tv.setOnTouchListener(this); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it // is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onTouch(View arg0, MotionEvent event) { Intent intent = new Intent(this, ThirdActivity.class); intent.putExtra("message", "20175205"); startActivity(intent); return true; } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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:layout_gravity="center" android:gravity="center_horizontal" android:padding="120dp" android:orientation="vertical" tools:context=".MainActivity"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:layout_marginTop="16dp" android:paddingLeft="16dp" android:paddingRight="16dp" android:text="20175205侯穎" android:id="@+id/btn1" /> </LinearLayout>
package com.example.administrator.ui; import android.content.Context; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.app.Activity; import android.util.AttributeSet; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btnshow1=(Button) findViewById(R.id.btn1); btnshow1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v){ Toast toast = Toast.makeText(MainActivity.this,"20165318孫曉暄", Toast.LENGTH_LONG); toast.show(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it // is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } /* @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id. id_action_add: //事件 break; case R.id. id_action_delete: //事件 break; } return true; }*/ }
Q:ERROR: Not enough disk space to run AVD 'Pixel_2_XL_API_26'. Exiting...
java
A:是說安裝模擬的磁盤空間不足,致使沒法運行模擬器
解決方案:默認的模擬器安裝在C盤中,能夠打開模擬器管理界面AVD Manager,右鍵查看(show ondisk)模擬器的安裝目錄,將模擬器放入空間足夠的磁盤中,而後修改路徑android
Q:Error:Cause: buildToolsVersion is not specified.
A:緣由是build.gradle中沒有buildToolsVersion
解決方案:在build.gradle中添加: buildToolsVersion 「28.0.3」
git
Q:menu爲何是紅色的。。。
app
A:在res目錄下添加menu文件夾,再添加xml佈局文件
ide