Kyou/layout #3
| 
						 | 
					@ -1,14 +1,18 @@
 | 
				
			||||||
package com.example.childguard;
 | 
					package com.example.childguard;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import android.content.SharedPreferences;
 | 
					import android.content.SharedPreferences;
 | 
				
			||||||
 | 
					import android.graphics.Color;
 | 
				
			||||||
 | 
					import android.graphics.drawable.Drawable;
 | 
				
			||||||
import android.os.Bundle;
 | 
					import android.os.Bundle;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import androidx.core.content.res.ResourcesCompat;
 | 
				
			||||||
import androidx.fragment.app.Fragment;
 | 
					import androidx.fragment.app.Fragment;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import android.util.Log;
 | 
					import android.util.Log;
 | 
				
			||||||
import android.view.LayoutInflater;
 | 
					import android.view.LayoutInflater;
 | 
				
			||||||
import android.view.View;
 | 
					import android.view.View;
 | 
				
			||||||
import android.view.ViewGroup;
 | 
					import android.view.ViewGroup;
 | 
				
			||||||
 | 
					import android.widget.FrameLayout;
 | 
				
			||||||
import android.widget.TextView;
 | 
					import android.widget.TextView;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
| 
						 | 
					@ -70,17 +74,20 @@ public class HomeFragment extends Fragment {
 | 
				
			||||||
        super.onResume();
 | 
					        super.onResume();
 | 
				
			||||||
        Log.d("HomeFragment", "onResume: called");
 | 
					        Log.d("HomeFragment", "onResume: called");
 | 
				
			||||||
        TextView situationTextView = getView().findViewById(R.id.situation);
 | 
					        TextView situationTextView = getView().findViewById(R.id.situation);
 | 
				
			||||||
        updateInCarStatus(situationTextView);
 | 
					        FrameLayout situation_bg=getView().findViewById(R.id.situation_bg);
 | 
				
			||||||
 | 
					        updateInCarStatus(situationTextView,situation_bg);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void updateInCarStatus(TextView situationTextView) {
 | 
					    public void updateInCarStatus(TextView situationTextView,FrameLayout situation_bg) {
 | 
				
			||||||
        SharedPreferences sharedPreferences = getActivity().getSharedPreferences("default", 0);
 | 
					        SharedPreferences sharedPreferences = getActivity().getSharedPreferences("default", 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Log.d("HomeFragment", "updateInCarStatus: " + sharedPreferences.getBoolean("inCar", false));
 | 
					        Log.d("HomeFragment", "updateInCarStatus: " + sharedPreferences.getBoolean("inCar", false));
 | 
				
			||||||
        if (sharedPreferences.getBoolean("inCar", false)) {
 | 
					        if (sharedPreferences.getBoolean("inCar", false)) {
 | 
				
			||||||
            situationTextView.setText("\n降車状態");
 | 
					            situationTextView.setText("\n降車状態");
 | 
				
			||||||
 | 
					            situation_bg.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.frame_style, null));
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            situationTextView.setText("\n乗車状態");
 | 
					            situationTextView.setText("\n乗車状態");
 | 
				
			||||||
 | 
					            situation_bg.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.frame_style_orange, null));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										7
									
								
								app/src/main/res/drawable/frame_style_orange.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								app/src/main/res/drawable/frame_style_orange.xml
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,7 @@
 | 
				
			||||||
 | 
					<?xml version="1.0" encoding="utf-8"?>
 | 
				
			||||||
 | 
					<shape xmlns:android="http://schemas.android.com/apk/res/android"
 | 
				
			||||||
 | 
					    android:shape="rectangle">
 | 
				
			||||||
 | 
					    <solid android:color="#ffa500"/>
 | 
				
			||||||
 | 
					    <corners android:radius="25dp"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</shape>
 | 
				
			||||||
| 
						 | 
					@ -7,7 +7,6 @@
 | 
				
			||||||
    android:layout_height="match_parent"
 | 
					    android:layout_height="match_parent"
 | 
				
			||||||
    android:orientation="vertical"
 | 
					    android:orientation="vertical"
 | 
				
			||||||
    tools:context=".HomeFragment">
 | 
					    tools:context=".HomeFragment">
 | 
				
			||||||
 | 
					 | 
				
			||||||
    <FrameLayout
 | 
					    <FrameLayout
 | 
				
			||||||
        android:id="@+id/situation_bg"
 | 
					        android:id="@+id/situation_bg"
 | 
				
			||||||
        android:layout_width="match_parent"
 | 
					        android:layout_width="match_parent"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user