master
liuyx 2 years ago
parent be0f1dbf04
commit 0f84b49747

@ -11,24 +11,24 @@
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication"
tools:targetApi="31">
<activity
android:name=".UserInfoActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".RegisterActivity"
android:exported="false" />
<activity
android:name=".LoginActivity"
android:exported="false" />
</application>
</manifest>

@ -0,0 +1,45 @@
package cc.liuyx.app;
import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import cc.liuyx.app.fragment.MainFragment;
import cc.liuyx.app.fragment.InfoFragment;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences preferences = getSharedPreferences("loginStatus", MODE_PRIVATE);
Log.i("log", preferences.getString("username", "no name"));
}
@SuppressLint("NonConstantResourceId")
public void selectFragment(View view) {
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
MainFragment firstFragment = new MainFragment();
InfoFragment infoFragment = new InfoFragment();
switch (view.getId()) {
case R.id.page_main:
ft.replace(R.id.page_blank, firstFragment);
break;
case R.id.page_info:
ft.replace(R.id.page_blank, infoFragment);
break;
}
ft.commit();
}
}

@ -53,7 +53,7 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
}
private void validateRegister() {
Intent intent = new Intent(RegisterActivity.this, UserInfoActivity.class);
Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
username = usernameEdit.getText().toString();
passwd = passwdEdit.getText().toString();

@ -0,0 +1,19 @@
package cc.liuyx.app.fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
import cc.liuyx.app.R;
public class InfoFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_info, container, false);
}
}

@ -0,0 +1,19 @@
package cc.liuyx.app.fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
import cc.liuyx.app.R;
public class MainFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_main, container, false);
}
}

@ -0,0 +1,43 @@
<?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"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/page_blank"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="19" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:textAlignment="center"
android:id="@+id/page_main"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="主页"
android:layout_weight="1"
android:textSize="@dimen/normal_font_size"
android:onClick="selectFragment" />
<TextView
android:textAlignment="center"
android:id="@+id/page_info"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="我的"
android:layout_weight="1"
android:textSize="@dimen/normal_font_size"
android:onClick="selectFragment" />
</LinearLayout>
</LinearLayout>

@ -0,0 +1,207 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".fragment.InfoFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:ignore="UselessParent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:layout_marginBottom="30dp"
android:gravity="center">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/ic_avatar" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_infoitem"
android:gravity="center">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_user" />
<TextView
android:id="@+id/user_username"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8"
android:text=" 用户名:"
android:textSize="@dimen/normal_font_size" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_weight="1"
android:src="@drawable/ic_arrow_right" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_infoitem"
android:gravity="center">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_phone" />
<TextView
android:id="@+id/user_phone"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8"
android:text=" 手机号:"
android:textSize="@dimen/normal_font_size" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_weight="1"
android:src="@drawable/ic_arrow_right" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:background="@drawable/shape_infoitem"
android:gravity="center">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_email" />
<TextView
android:id="@+id/user_email"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8"
android:text=" 邮箱:"
android:textSize="@dimen/normal_font_size" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_weight="1"
android:src="@drawable/ic_arrow_right" />
</LinearLayout>
<LinearLayout
android:id="@+id/user_setting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:background="@drawable/shape_infoitem"
android:gravity="center">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_setting" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8"
android:text=" 设置"
android:textSize="@dimen/normal_font_size" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_weight="1"
android:src="@drawable/ic_arrow_right" />
</LinearLayout>
<LinearLayout
android:id="@+id/more"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_infoitem"
android:gravity="center">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_more" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8"
android:text=" 更多"
android:textSize="@dimen/normal_font_size" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_weight="1"
android:src="@drawable/ic_arrow_right" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center">
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/logout"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_above="@+id/footnote"
android:layout_centerHorizontal="true"
android:layout_marginBottom="30dp"
android:text="退出登录" />
<TextView
android:id="@+id/footnote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:text="@string/footnote"
android:textAlignment="center" />
</RelativeLayout>
</LinearLayout>
</FrameLayout>

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".fragment.MainFragment">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="这是主页!" />
</FrameLayout>

@ -9,7 +9,7 @@
android:id="@+id/FirstFragment"
android:name="com.example.myapplication.FirstFragment"
android:label="@string/first_fragment_label"
tools:layout="@layout/fragment_first">
tools:layout="@layout/fragment_main">
<action
android:id="@+id/action_FirstFragment_to_SecondFragment"

@ -9,7 +9,7 @@
android:id="@+id/FirstFragment"
android:name="com.example.myapplication.FirstFragment"
android:label="@string/first_fragment_label"
tools:layout="@layout/fragment_first" >
tools:layout="@layout/fragment_main">
<action
android:id="@+id/action_FirstFragment_to_SecondFragment"
@ -19,7 +19,7 @@
android:id="@+id/SecondFragment"
android:name="com.example.myapplication.SecondFragment"
android:label="@string/second_fragment_label"
tools:layout="@layout/fragment_second" >
tools:layout="@layout/fragment_second">
<action
android:id="@+id/action_SecondFragment_to_FirstFragment"

@ -12,4 +12,6 @@
<string name="title_activity_register">RegisterActivity</string>
<string name="footnote">联系我liuyxcc@gmail.com</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>
Loading…
Cancel
Save