目錄
一、測試環境說明
二、項目簡介
三、項目演示
四、部設計詳情(部分)
登錄注冊頁
首頁
五、項目源碼?
一、測試環境說明
電腦環境
Windows 11
編寫語言
JAVA
開發軟件
Android Studio ?(2020)
開發軟件只要大于等于測試版本即可(近幾年官網直接下載也可以),若是版本低于測試版本請自行測試。項目需要根據你的軟件自行適配
二、項目簡介
該項目簡介來自網絡,具體內容需要自行測試
本項目是一個基于Android平臺的圖書商城應用,采用Java語言開發,使用SQLite作為本地數據庫存儲方案。
系統實現了完整的電子商務功能流程,包括用戶注冊登錄、圖書分類瀏覽、商品詳情查看、購物車管理、訂單生成與查詢等功能模塊。
應用采用MVC架構設計,通過RecyclerView實現高性能列表展示,并利用Navigation組件管理頁面導航。在界面設計上,遵循Material Design規范,使用CardView、FloatingActionButton等現代化UI組件提升用戶體驗。
系統特別設計了分類導航功能,用戶可以按計算機、小說、科學、歷史等分類瀏覽圖書,并通過購物車批量管理選購商品。
訂單模塊完整記錄了購買歷史,支持訂單詳情查看和刪除操作。整個應用充分考慮了移動端特性,實現了流暢的用戶交互和穩定的數據存儲,為讀者提供了便捷的圖書購買體驗。
該項目由編程樂學團隊介入,優化布局完善功能
三、項目演示
網絡資源模板--基于Android studio 圖書商城App
四、部設計詳情(部分)
登錄注冊頁
1. 頁面結構
該頁面采用單Activity結構,核心布局由ConstraintLayout構成,內部嵌套MaterialCardView作為登錄卡片容器。
卡片內采用垂直LinearLayout組織UI元素,包含標題、用戶名輸入框、密碼輸入框、登錄按鈕和注冊切換鏈接。整體采用居中卡片設計,背景可自定義,輸入框使用Material Design的TextInputLayout實現浮動標簽效果,按鈕采用MaterialButton保持風格統一。
布局層次清晰,間距合理,符合Material Design設計規范。
2. 使用技術
頁面采用AndroidX組件庫,使用Material Design組件實現現代化UI,包括MaterialCardView、TextInputLayout和MaterialButton。
數據持久化通過SharedPreferences實現用戶名記憶功能。采用MVC模式組織代碼,將認證邏輯封裝在MyAuth類中。
使用Intent實現頁面跳轉,并配合清理返回棧。輸入驗證包括非空檢查和錯誤焦點管理,通過Toast提供用戶反饋。
3. 頁面功能詳解
該頁面提供雙模式切換功能,可在登錄和注冊狀態間無縫轉換。登錄模式下驗證用戶憑證,注冊模式檢查用戶名唯一性。
自動記憶上次成功登錄的用戶名提升用戶體驗。輸入驗證確保必填字段完整性,錯誤時自動聚焦對應字段。
認證成功后會清除導航棧直接進入主界面,防止用戶回退到登錄頁。
整體交互流暢,錯誤處理完善,遵循Material Motion動效原則,視覺層次分明,色彩使用符合Material Design調色板規范。
package com.example.shop.controllers;import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;import androidx.appcompat.app.AppCompatActivity;import com.example.shop.MyAuth;
import com.example.shop.R;/*** 登錄/注冊Activity,處理用戶認證流程* 功能:* 1. 登錄/注冊模式切換* 2. 賬號密碼非空驗證* 3. 自動填充已保存的用戶名* 4. 成功登錄后跳轉主界面*/
public class LoginActivity extends AppCompatActivity implements View.OnClickListener {// UI組件private TextView loginTitle;private Button authButton;private TextView toggleAuthMode;private EditText usernameInput;private EditText passwordInput;// 當前模式標志,true為登錄模式,false為注冊模式private boolean isLoginMode = true;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// 隱藏ActionBarif (getSupportActionBar() != null) {getSupportActionBar().hide();}setContentView(R.layout.activity_login);// 初始化UI組件initViews();// 檢查是否有保存的用戶名,有則自動填充checkSavedUsername();}/*** 初始化所有視圖組件*/private void initViews() {loginTitle = findViewById(R.id.loginTitle);authButton = findViewById(R.id.loginButton);toggleAuthMode = findViewById(R.id.toggleLoginReg);usernameInput = findViewById(R.id.editTextTextEmailAddress);passwordInput = findViewById(R.id.editTextTextPassword);// 設置點擊監聽器toggleAuthMode.setOnClickListener(this);authButton.setOnClickListener(this);}/*** 檢查SharedPreferences中是否有保存的用戶名*/private void checkSavedUsername() {SharedPreferences sp = getSharedPreferences("preferences", MODE_PRIVATE);String savedUsername = sp.getString("username", "");if (!savedUsername.isEmpty()) {usernameInput.setText(savedUsername);// 自動聚焦到密碼輸入框passwordInput.requestFocus();}}/*** 跳轉到主Activity并清除返回棧*/private void navigateToMain() {Intent intent = new Intent(this, MainActivity.class);intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);startActivity(intent);finish(); // 結束當前Activity}/*** 切換登錄/注冊模式*/private void toggleAuthMode() {isLoginMode = !isLoginMode;loginTitle.setText(isLoginMode ? "登錄" : "注冊");authButton.setText(isLoginMode ? "登錄" : "注冊");toggleAuthMode.setText(isLoginMode ? "立即注冊" : "立即登錄");// 清空密碼輸入框passwordInput.setText("");}/*** 驗證輸入是否有效* @return true表示有效,false表示無效*/private boolean validateInput() {String username = usernameInput.getText().toString().trim();String password = passwordInput.getText().toString().trim();if (username.isEmpty()) {showToast("賬號不能為空");usernameInput.requestFocus();return false;}if (password.isEmpty()) {showToast("密碼不能為空");passwordInput.requestFocus();return false;}return true;}/*** 處理登錄邏輯*/private void handleLogin() {if (!validateInput()) {return;}String username = usernameInput.getText().toString().trim();String password = passwordInput.getText().toString().trim();MyAuth auth = new MyAuth(this);MyAuth.AuthResult result = auth.authUser(username, password);switch (result) {case SUCCESS:saveUsername(username);navigateToMain();break;case INVALID_USERNAME_OR_PWD:showToast("用戶名或密碼錯誤");passwordInput.setText("");passwordInput.requestFocus();break;case TOKEN_TOO_LONG:showToast("用戶名太長");usernameInput.requestFocus();break;case UNKNOWN_ERROR:showToast("出現未知錯誤");break;}}/*** 處理注冊邏輯*/private void handleRegistration() {if (!validateInput()) {return;}String username = usernameInput.getText().toString().trim();String password = passwordInput.getText().toString().trim();MyAuth auth = new MyAuth(this);MyAuth.AuthResult result = auth.addUser(username, password);switch (result) {case SUCCESS:saveUsername(username);navigateToMain();break;case USER_EXISTED:showToast("用戶已存在");usernameInput.requestFocus();break;case TOKEN_TOO_LONG:showToast("用戶名太長");usernameInput.requestFocus();break;case UNKNOWN_ERROR:showToast("出現未知錯誤");break;}}/*** 保存用戶名到SharedPreferences* @param username 要保存的用戶名*/private void saveUsername(String username) {SharedPreferences sp = getSharedPreferences("preferences", MODE_PRIVATE);sp.edit().putString("username", username).apply();}/*** 顯示Toast消息* @param message 要顯示的消息*/private void showToast(String message) {Toast.makeText(this, message, Toast.LENGTH_SHORT).show();}@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.toggleLoginReg:toggleAuthMode();break;case R.id.loginButton:if (isLoginMode) {handleLogin();} else {handleRegistration();}break;}}
}
首頁
1. 頁面結構
該頁面采用垂直LinearLayout布局,頂部為橫向滾動的分類導航欄(HorizontalScrollView),底部為RecyclerView展示圖書列表。
分類導航欄使用CardView包裹,內部動態生成分類標簽卡片。RecyclerView采用GridLayoutManager實現網格布局,支持分類標題跨列顯示。
頁面結構分為上下兩部分,上方分類導航可點擊切換,下方圖書列表支持點擊跳轉詳情。整體布局簡潔高效,分類導航與內容區域聯動,提供流暢的瀏覽體驗。
2. 使用技術
頁面基于AndroidX組件庫,使用RecyclerView實現高性能列表展示,配合GridLayoutManager實現網格布局。
采用自定義SpanSizeLookup處理分類標題的跨列顯示。數據層通過BookService獲取圖書信息,使用HashMap按分類組織數據。
導航采用Navigation組件實現Fragment間跳轉。交互方面實現了RecyclerView滾動監聽與分類導航聯動,通過動態修改CardView背景色指示當前分類。整體采用觀察者模式處理滾動事件,實現雙向導航交互。
3. 頁面功能詳解
該頁面是圖書分類瀏覽界面,頂部導航欄展示所有圖書分類,點擊可快速定位到對應分類。圖書列表按分類分組顯示,每個分類標題占據整行,圖書以網格形式展示。
滾動列表時導航欄會自動高亮當前分類,反之點擊導航欄也會滾動到對應分類。每本圖書可點擊進入詳情頁。
頁面采用內存優化設計,動態加載分類導航標簽,通過位置映射表高效管理分類定位。視覺上通過卡片陰影和顏色對比強化交互反饋,提供直觀的分類瀏覽體驗。
<?xml version="1.0" encoding="utf-8"?>
<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"><androidx.cardview.widget.CardViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="0"app:cardCornerRadius="0dp"app:cardElevation="4dp"><HorizontalScrollViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="0"><LinearLayoutandroid:id="@+id/linear_pager"android:layout_width="wrap_content"android:layout_height="match_parent"android:layout_gravity="start"android:orientation="horizontal"android:paddingStart="6dp"android:paddingEnd="6dp"><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="TextView" /></LinearLayout></HorizontalScrollView></androidx.cardview.widget.CardView><androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/book_list"android:name="com.example.shop.BookFragment"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"app:layoutManager="LinearLayoutManager"tools:context=".controllers.BookFragment"tools:listitem="@layout/book_fragment_item"></androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
五、項目源碼?
👇👇👇👇👇快捷方式👇👇👇👇👇