parent
							
								
									be0f1dbf04
								
							
						
					
					
						commit
						0f84b49747
					
				| @ -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(); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -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> | ||||||
					Loading…
					
					
				
		Reference in new issue