安装apk:
开发完成后,需要buildAPK,再次发送才能运行。
adb install -r (apk完整路径) 安装在第三方app
系统级app需要打包apk,浦西
卸载apk:adb uninstall (apk包名)
卸载app但保留数据和缓存文件:adb uninstall -k (apk包名)
列出所有的手机app包名:adb shell pm list packages
线性布局:LinearLayout
<?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:orientation="vertical" tools:context=".MainActivity" android:gravity="center_vertical|bottom"> <LinearLayout android:id="@ id/tzs_1" android:layout_width="200dp" android:layout_height="200dp" android:orientation="vertical" android:background="#000000" android:paddingLeft="20dp" android:paddingRight="20dpspan class="token punctuation">" android:paddingTop="20dp" android:paddingBottom="20dp" android:layout_marginBottom="20dp">
<View android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FF0033">
</View>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="200dp" android:background="#0066FF" android:orientation="horizontal" android:layout_marginLeft="15dp" android:layout_marginRight="15dp">
<View android:layout_width="0dp" android:layout_height="match_parent" android:background="#000000" android:layout_weight="1">
</View>
<View android:layout_width="0dp" android:layout_height="match_parent" android:background="#FF0033" android:layout_weight="1">
</View>
<View android:layout_width="0dp" android:layout_height="match_parent" android:background="#55AA99" android:layout_weight="1">
</View>
</LinearLayout>
</LinearLayout>
针对于不同的地方使用不同的gravity,其效果不同。
<?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" android:gravity="center_vertical|left">
<!--android:gravity:规范整个布局内的元素进行规范-->
<TextView android:layout_width="100dp" android:layout_height="100dp" android:layout_gravity="right" android:gravity="left|bottom" android:text="@string/tv_test1" />
<!--android:layout_gravity:可以进行让布局内元素改变 android:gravity:规范字体的布局-->
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第二行"/>
</LinearLayout>
相对布局:RelativeLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent">
<View android:id="@+id/view_1" android:layout_width="100dp" android:layout_height="100dp" android:background="#000000"黑 android:layout_alignParentBottom="true" android:layout_alignParentRight="true"/>
<View android:id="@+id/view_2" android:layout_width="100dp" android:layout_height="100dp" android:background="#00ff00"绿/>
<View android:id="@+id/view_3" android:layout_width="100dp" android:layout_height="100dp" android:background="#FF0033" android:layout_below="@id/view_2"/>
<LinearLayout android:id="@+id/view_4" android:layout_width="match_parent" android:layout_height="100dp" android:layout_below="@+id/view_3" android:background="#0066FF"红 android:orientation="horizontal" android:padding="15dp">
<View android:layout_width="100dp" android:layout_height="match_parent" android:background="#FF0033"红/>
<RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="#000000"黑 android:padding="15dp">
<View android:id="@+id/view_5" android:layout_width="100dp" android:layout_height="match_parent" android:background="#FF9900"橙/>
<View android:id="@+id/view_6" android:layout_width="100dp" android:layout_height="match_parent" android:layout_marginLeft="10dp" android:layout_toRightOf="@id/view_5" android:background="#FF9900"橙/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
TextView:
项目中新添加一个TextViewActivity
设置一个Button按钮—activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
<Button android:id="@+id/btn_textview" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="TextView"/>
</LinearLayout>
MainActivity:
public class MainActivity extends AppCompatActivity {
//1.申明Button
private Button mBtnTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//2.寻找到Button
mBtnTextView = findViewById(R.id.btn_textview);
//3.设置点击事件
mBtnTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//跳转到TextView演示界面
Intent intent = new Intent(MainActivity.this, TextViewActivity.class);
startActivity(intent);
}
});
}
}
activity_text_view.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="20dp">
<TextView android:id="@+id/tv_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/tv_test1" android:textColor="#000000" android:textSize="24sp"/>
<TextView android:id="@+id/tv_2" android:layout_width="120dp" android:layout_height="wrap_content" android:maxLines="1" android:ellipsize="end" android:text="@string/tv_test1" android:textColor="#000000" android:textSize="24sp" android:layout_marginTop="10dp"/>
<TextView android:id="@+id/tv_3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:drawablePadding="5dp" android:drawableRight="@drawable/move_down" android:text="筛选" android:textColor="#000000" android:textSize="24sp" />
<TextView android:id="@+id/tv_4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/tv_test1" android:layout_marginTop="10dp" android:textColor="#000000" android:textSize="24sp" />
<TextView android:id="@+id/tv_5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/tv_test1" android:layout_marginTop="10dp" android:textColor="#000000" android:textSize="24sp"/>
<TextView android:id="@+id/tv_6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:textColor="#000000" android:textSize="24sp" />
<TextView android:id="@+id/tv_7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="谭章竦在奔跑谭章竦在奔跑谭章竦在奔跑谭章竦在奔跑谭章竦在奔跑" android:layout_marginTop="10dp" android:textColor="#000000" android:textSize="24sp" android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:focusable="true" android:focusableInTouchMode="true" android:clickable="true"/>
</LinearLayout>
TextViewActivity:
public class TextViewActivity extends AppCompatActivity {
//1.申明textView
// 设置中划线
private TextView mTv4;
// 设置下划线
private TextView mTv5;
// 设置下划线
private TextView mTv6;
// 设置跑马灯
private TextView mTv7;
@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);
//设置下划线
mTv5 = findViewById(R.id.tv_5);
mTv5.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
//设置下划线
mTv6 = findViewById(R.id.tv_6);
mTv6.setText(Html.fromHtml("<u>谭章竦学习中</u>"));
//设置跑马灯
mTv7 = findViewById(R.id.tv_7);
mTv7.setSelected(true);
}
}
UI控件跳转与显示点击
实现跳转和显示点击都有两种方式:
①实现接口implements View.OnClickListener,重写onClick方法
②匿名内部类new View.OnClickListener()
//匿名内部类,目前局限为只能设置一个事件。 public class MainActivity extends AppCompatActivity { //1.申明图片或按钮变量 private ImageView ivQq; @Override