欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

仿微信项目实战(一)

程序员文章站 2022-04-21 23:27:06
...

准备工具

1.新建项目

  • 打开Android Studio
  • 项目名称Phone
  • Minsdk-23
  • Targetsdk-28

2.res->vealue->colors.xml

<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#008577</color>
    <color name="colorPrimaryDark">#00574B</color>
    <color name="colorAccent">#D81B60</color>

    <color name="bg">#F2EEE8</color>
    <color name="title_text_color">#ffffffff</color>
    <color name="input_bg">#ffffffff</color>

    <color name="dialog_item_normal">#ffffffff</color>
    <color name="dialog_item_press">#33333333</color>
    <color name="dialog_bg">#00000000</color>
</resources>

3.demins.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>
    <dimen name="title_bar_height">48dp</dimen>
    <dimen name="preview_width">80dp</dimen>
    <dimen name="preview_height">80dp</dimen>
    <dimen name="preview_margin_right">10dp</dimen>

</resources>

4.style.xml

<resources>

    <!-- Base application theme. -->

    <style name="AppBaseTheme" parent="android:Theme.Light"></style>

    <style name="AppTheme" parent="AppBaseTheme">
        <item name="android:windowNoTitle">true</item>
    </style>

    <style name="title_text">
        <item name="android:textSize">18sp</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">@color/title_text_color</item>
    </style>

    <style name="bar_button_left">
        <item name="android:layout_alignParentLeft">true</item>
        <item name="android:layout_width">20dp</item>
        <item name="android:layout_height">20dp</item>
        <item name="android:layout_marginLeft">10dp</item>
        <item name="android:layout_centerVertical">true</item>
    </style>

    <style name="dialog_item_text">
        <item name="android:gravity">center</item>
        <item name="android:textColor">#000000</item>
        <item name="android:textSize">16sp</item>
        <item name="android:background">@drawable/dialog_item_backgroud</item>
    </style>
</resources>

5.导入素材图片

  • add_img_icon.png
  • back.png
  • bar.png

仿微信项目实战(一)

6.编辑页面布局文件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">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/title_bar_height"
        android:background="@drawable/bar">

        <TextView
            style="@style/title_text"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_centerHorizontal="true"
            android:gravity="center"
            android:text="项目实战"></TextView>

        <Button
            style="@style/bar_button_left"
            android:background="@drawable/back"
            android:onClick="back" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:background="@null"
            android:onClick="submit"
            android:text="发表"
            android:textColor="@color/title_text_color" />
    </RelativeLayout>

    <EditText
        android:id="@+id/talk"
        android:layout_width="match_parent"
        android:layout_height="140dp"
        android:background="@color/input_bg"
        android:gravity="top"
        android:hint="说点什么吧..." />

    <LinearLayout
        android:id="@+id/preview_group"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="20dp"
        android:background="@color/input_bg"
        android:orientation="horizontal"
        android:padding="10dp">

        <ImageView
            android:layout_width="@dimen/preview_width"
            android:layout_height="@dimen/preview_height"
            android:onClick="addImg"
            android:src="@drawable/add_img_icon" />
    </LinearLayout>

</LinearLayout>
  • 效果如图所示
    仿微信项目实战(一)

7.编辑Activiy.main文件

package edu.qau.phone;

import android.app.Activity;

public class MainActivity extends Activity {
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}