首次提交

This commit is contained in:
DelLevin-Home
2026-02-08 22:31:32 +08:00
commit 7dc79172fa
54 changed files with 1403 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
package top.iletter.lvnote;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;
import com.google.android.material.tabs.TabLayout;
public class FragmentHome extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_home, container, false);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
TabLayout tabLayout = view.findViewById(R.id.tab_layout);
ViewPager2 viewPager = view.findViewById(R.id.view_pager);
// 设置三标签:看过/正在看/准备看
tabLayout.addTab(tabLayout.newTab().setText("看过"));
tabLayout.addTab(tabLayout.newTab().setText("正在看"));
tabLayout.addTab(tabLayout.newTab().setText("准备看"));
// TODO: 后续实现 ViewPager2 适配器
}
}

View File

@@ -0,0 +1,39 @@
package top.iletter.lvnote;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
public class FragmentProfile extends Fragment {
// ⚠️ 必须有无参构造函数!
public FragmentProfile() {
// Required empty public constructor
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_profile, container, false);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// 安全地操作 View
TextView movieCount = view.findViewById(R.id.tv_movie_count);
TextView bookCount = view.findViewById(R.id.tv_book_count);
if (movieCount != null) movieCount.setText("24");
if (bookCount != null) bookCount.setText("18");
}
}

View File

@@ -0,0 +1,68 @@
package top.iletter.lvnote;
import android.os.Bundle;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.Fragment;
import com.google.android.material.bottomappbar.BottomAppBar;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private FragmentHome homeFragment = new FragmentHome();
private FragmentProfile profileFragment = new FragmentProfile();
private Fragment currentFragment = homeFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 初始化默认显示主页
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container, homeFragment)
.commit();
}
// 左按钮:主页
ImageButton btnHome = findViewById(R.id.btn_home);
btnHome.setOnClickListener(v -> switchFragment(homeFragment));
// 右按钮:我的
ImageButton btnProfile = findViewById(R.id.btn_profile);
btnProfile.setOnClickListener(v -> switchFragment(profileFragment));
// 中间按钮:添加
FloatingActionButton fabAdd = findViewById(R.id.fab_add);
fabAdd.setOnClickListener(v -> {
// TODO: 跳转到新增页面
Toast.makeText(this, "点击了添加按钮", Toast.LENGTH_SHORT).show();
});
}
private void switchFragment(Fragment targetFragment) {
if (currentFragment != targetFragment) {
getSupportFragmentManager().beginTransaction()
.setCustomAnimations(
android.R.anim.fade_in,
android.R.anim.fade_out,
android.R.anim.fade_in,
android.R.anim.fade_out
)
.replace(R.id.fragment_container, targetFragment)
.commit();
currentFragment = targetFragment;
}
}
}