2017-11-16 5 views
0

주요 활동에는 회 전자와 버튼이 있습니다. MainActivity.java 코드는 다음과 같습니다. (activity_main.xml)를 다음과 같이Android : 전체 화면 종료 후 기본 활동으로 돌아 가기

public class MainActivity extends AppCompatActivity implements LoadNew.VCallback { 
 

 
    public Spinner dropdown; 
 

 
    @Override 
 
    protected void onCreate(Bundle savedInstanceState) { 
 
     super.onCreate(savedInstanceState); 
 
     setContentView(R.layout.activity_main); 
 
     dropdown = (Spinner) findViewById(R.id.spinner1); 
 

 
     //Create a list of items for the spinner. 
 
     String[] items = new String[]{"select topic", "topic1", "topic2"}; 
 
     ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, items); 
 
     dropdown.setAdapter(adapter); 
 
     dropdown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 
 

 
      @Override 
 
      public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) { 
 
       // TODO Auto-generated method stub 
 
       String sp1 = String.valueOf(dropdown.getSelectedItem()); 
 
       if (sp1.contentEquals("select topic")) { 
 
        loadFun(""); 
 
       } 
 
       if (sp1.contentEquals("topic1")) { 
 
        loadFun("topic1"); 
 
       } 
 
       if (sp1.contentEquals("topic2")) { 
 
        loadFun("topic2"); 
 
       } 
 
      } 
 

 
      @Override 
 
      public void onNothingSelected(AdapterView<?> parentView){ 
 
       // TODO Auto-generated method stub 
 
      } 
 
     }); 
 

 
     Button x = (Button) findViewById(R.id.full_screen); 
 
     x.setOnClickListener(new View.OnClickListener() { 
 
      @Override 
 
      public void onClick(View v) { 
 
       loadFun("topic2", 0); 
 
      } 
 
     }); 
 
    } 
 

 
    public void loadFun(String topicName, int i) { 
 
     LoadNew st = new LoadNew(this); 
 
     st.display(topicName, i); 
 
    } 
 
}

주요 활동에 대한 XML 레이아웃이다.

<?xml version="1.0" encoding="utf-8"?> 
 
<RelativeLayout 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" 
 
android:orientation="vertical"> 
 
    <LinearLayout 
 
     android:layout_width="match_parent" 
 
     android:layout_height="match_parent" 
 
     android:orientation="vertical"> 
 

 
     <LinearLayout 
 
      android:layout_width="match_parent" 
 
      android:layout_height="wrap_content" 
 
      android:orientation="horizontal" > 
 
      <Spinner 
 
       android:id="@+id/spinner1" 
 
       android:layout_width="match_parent" 
 
       android:layout_height="wrap_content" 
 
       android:background="@android:drawable/btn_dropdown" 
 
       android:spinnerMode="dropdown" /> 
 
     </LinearLayout> 
 
     <LinearLayout 
 
      android:layout_width="match_parent" 
 
      android:layout_height="wrap_content" 
 
      android:orientation="horizontal" > 
 
      <Button 
 
       android:id="@+id/full_screen" 
 
       android:layout_width="match_parent" 
 
       android:layout_height="wrap_content" 
 
       android:text="Full Screen" 
 
       style="?android:attr/borderlessButtonStyle"/> 
 
     </LinearLayout> 
 
     <LinearLayout 
 
      android:id="@+id/full_view" 
 
      android:layout_width="match_parent" 
 
      android:layout_height="wrap_content" 
 
      android:orientation="horizontal" > 
 
     </LinearLayout> 
 

 
    </LinearLayout> 
 
</RelativeLayout>

다음과 같은 다른 자바 클래스 LoadNew.java이 있습니다

. 다음과 같이

public class LoadNew { 
 

 
    public interface VCallback { 
 
     //To access methods of MainActivity class 
 
    } 
 

 
    public Activity activity; 
 

 
    public LoadNew(Activity _activity) { 
 
     this.activity = _activity; 
 
     VCallback callerActivity = (VCallback) activity; 
 

 
    } 
 

 
    //Display PDF 
 
    public void display(String topicName, int i) { 
 
     LinearLayout fullScreen = (LinearLayout) this.activity.findViewById(R.id.full_view); 
 
     fullScreen.removeAllViews();//Clear field 
 
     LayoutInflater inflater = (LayoutInflater) this.activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
 

 
     View view = inflater.inflate(R.layout.activity_load, null); 
 
     if(i ==0) { 
 
     this.activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 
 
      this.activity.setContentView(view); 
 
     } 
 
     TextView tv= (TextView) this.activity.findViewById(R.id.tv1); 
 
     tv.setText(topicName); 
 
     tv.setTextSize(100); 
 
    } 
 
}

activity_load.xml 파일입니다.

항목을 스피너에서 선택

<?xml version="1.0" encoding="utf-8"?> 
 
<RelativeLayout> xmlns:android="http://schemas.android.com/apk/res/android" 
 
xmlns:tools="http://schemas.android.com/tools" 
 
android:orientation="vertical" 
 
android:layout_width="match_parent" 
 
android:layout_height="match_parent" 
 
tools:context=".MainActivity"> 
 

 
<TextView 
 
    android:id="@+id/tv1" 
 
    android:layout_below="@+id/bar" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="wrap_content"/> 
 

 
</RelativeLayout>

은 해당 텍스트가 텍스트 뷰에 표시된다. 버튼을 누르면 텍스트 뷰가 전체 화면 모드로 나타납니다. 이제 버튼을 클릭하기 전에 이전보기 (뒤로 버튼 또는 화면의 단일 탭 누름)로 돌아가고 싶습니다. 이것을 어떻게 할 수 있습니까? 인내와 도움에 미리 감사드립니다.

답변

0

가장 간단한 방법은 하나의 활동에 스피너와 전체 화면이 아닌 TextView를두고 버튼 클릭시 전체 화면 모드로 두 번째 활동을 여는 것입니다.

관련 문제