Andorid实例--仿外卖APP(未完成)

一.闪屏页实现

1.闪屏页面

public class SplashActivity extends AppCompatActivity {

private Button btn;
private Handler sphandler = new Handler();
private Runnable spRunnabletoLogin = new Runnable() {
    @Override
    public void run() {

        toLoginactivity();
    }
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);
    //三秒后自动跳转
    sphandler.postDelayed(spRunnabletoLogin,10000);
    initView();
    initEvent();
}

private void initEvent() {
    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            toLoginactivity();
        }
    });
}

private void toLoginactivity() {
    Intent intent = new Intent(this,MainActivity.class);
    startActivity(intent);
    finish();
}

private void initView() {
    btn = findViewById(R.id.tg_btn);
}
//销毁时关闭Handler 防止内存泄漏
@Override
protected void onDestroy() {
    sphandler.removeCallbacks(spRunnabletoLogin);
    super.onDestroy();
}

}

2.布局

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="com.example.mr.ztakeoutdome.SplashActivity">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    >
    <LinearLayout
        android:id="@+id/splash_bg"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:orientation="vertical"
        >
        <View
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="@drawable/splash"
            />
    </LinearLayout>
    <Button
        android:id="@+id/tg_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/tg_text"
        android:layout_alignParentRight="true"
        android:minHeight="0dp"
        android:minWidth="0dp"
        android:background="@drawable/btn_bg_skip"
        android:paddingLeft="5dp"
        android:paddingRight="5dp"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"
        android:textColor="@color/colorbtn"
        android:textSize="14sp"
        />

</RelativeLayout>
</FrameLayout>

3.跳转按钮边框设置

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!--点击时-->
    <item android:state_pressed="true">
        <shape>
            <!--圆角半径-->
            <corners android:radius="8dp"></corners>
            <!--填充背景颜色-->
            <solid android:color="#aae7bfa0"></solid>
            <!--外边框-->
            <stroke android:width="1dp" android:color="#f56b09"></stroke>
    </shape>
</item>
<!--默认时-->
<item>
    <shape>
        <corners android:radius="8dp"></corners>
        <solid android:color="#AA444444"></solid>
        <stroke android:width="1dp" android:color="#b6b1b1"></stroke>

    </shape>
</item>

ps:标题栏设置

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#000000"
    app:navigationIcon="@drawable/back"
    app:titleTextColor="#ffffff"
    >

</android.support.v7.widget.Toolbar>

在页面布局中添加标题栏
<LinearLayout
    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"
    android:orientation="vertical"
    tools:context="com.example.mr.ztakeoutdome.RegisterActivity">
    <!--设置标题栏-->
    <include layout="@layout/common_toolbar"/>

        <EditText
            android:id="@+id/register_name"
            android:layout_height="56dp"
            android:layout_width="match_parent"
            android:hint="@string/registers_name"
            android:background="#44ffffff"
            android:layout_marginTop="50dp"

            />

猜你喜欢

转载自blog.csdn.net/weixin_43609490/article/details/87931633
今日推荐