2016-07-17 2 views
0

я занимаюсь разработкой Android App, который является полноэкранное приложение, в основной деятельности есть 2 кнопкиAndroid Полноэкранный вопрос

Этот вопрос когда я нажимаю на кнопку О Выдвижной активность появляются после щелчка на отклонять строке заголовка появится в основной деятельности, см захват экрана:

основной вид деятельности
The main activity

После нажатия кнопки О и нажав на отклонять
After clicking About button and clicking on dismiss

about_popout.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp" 
    android:orientation="vertical" 
    android:weightSum="100"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_margin="1dp" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:layout_weight="60" 
     android:background="@android:color/transparent" 
     android:gravity="center_vertical" 
     android:orientation="vertical" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_margin="1dp" 
      android:background="@drawable/about_shape" 
      android:gravity="center_vertical" 
      android:orientation="vertical" > 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_margin="20dp" 
       android:orientation="vertical" > 

       <TextView 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:textSize="12pt" 
        android:textColor="#FFFFFF" 
        android:text="It&apos;s a PopupWindow" /> 

       <ImageView 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:src="@drawable/common_ic_googleplayservices" /> 

       <Button 
        android:id="@+id/btn_dismiss" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:background="@android:color/transparent" 
        android:text="Dismiss" 
        android:textColor="#FFFFFF" /> 
      </LinearLayout> 
     </LinearLayout> 
    </LinearLayout> 

</LinearLayout> 

activity_main_menu.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:background="#ff5722" 
    android:orientation="vertical" 
    tools:context="com.game.circle.thecirclegame.MainMenu"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hello World!" 
     android:id="@+id/textView" /> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="To the Game" 
     android:id="@+id/startButton" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true" /> 

    <Button 
     android:id="@+id/btn_about" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="20px" 
     android:layout_marginLeft="100px" 
     android:layout_marginRight="100px" 
     android:text="About"/> 
</LinearLayout> 

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.game.circle.thecirclegame"> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 
     <activity android:name=".MainMenu"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:name=".GamePanel"></activity><!-- ATTENTION: This was auto-generated to add Google Play services to your project for 
    App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. --> 
     <meta-data 
      android:name="com.google.android.gms.version" 
      android:value="@integer/google_play_services_version" /> 
    </application> 

</manifest> 

Класс MainMenu.java, где появляется строка заголовка, после нажатия btn_about

package com.game.circle.thecirclegame; 

import android.content.Context; 
import android.content.Intent; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.Gravity; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.widget.Button; 
import android.widget.PopupWindow; 
import android.app.ActionBar.LayoutParams; 

public class MainMenu extends AppCompatActivity { 

    Button btn_startGame, btn_about; 
    final Context context = this; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     getWindow().getDecorView().setSystemUiVisibility(
       View.SYSTEM_UI_FLAG_LAYOUT_STABLE 
         | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 
         | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 
         | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 
         | View.SYSTEM_UI_FLAG_FULLSCREEN 
         | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); 
     setContentView(R.layout.activity_main_menu); 

     addListinerToButtons(); 

    } 

    public void addListinerToButtons(){ 

     btn_startGame = (Button)findViewById(R.id.startButton); 
     btn_about = (Button)findViewById(R.id.btn_about); 


     btn_startGame.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent intent = new Intent(context,GamePanel.class); 
       startActivity(intent); 
      } 
     }); 

     btn_about.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       LayoutInflater layoutInflater = (LayoutInflater) 
         getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE); 


       View popupView = layoutInflater.inflate(R.layout.about_popout, null); 
       final PopupWindow popupWindow = new PopupWindow(popupView, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, true); 
       popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0); 
       Button btn_dismiss = (Button)popupView.findViewById(R.id.btn_dismiss); 

       btn_dismiss.setOnClickListener(new View.OnClickListener() { 

        @Override 
        public void onClick(View v) { 
         // TODO Auto-generated method stub 
         popupWindow.dismiss(); 
        }}); 
       popupWindow.showAsDropDown(btn_about, 50, -30); 
      } 
     }); 

    } 
} 

мне нужно получить красные синий заголовок.

+0

ВЫ НИКОГДА не хотите показывать заголовок? –

+0

Просьба заполнить манифест. Вероятно, вы использовали тему ActionBar для этого действия (или по какой-то причине вы вызывали 'setToolbar') –

+0

И, кстати, в целях производительности не рекомендуется вложенные LinearLayout –

ответ

0

Проблема решена. Поскольку я не продолжал использовать всплывающее окно, Я создаю новую активность и переадресую кнопку из главного меню на «О деятельности»

1

Вы можете удалить строку заголовка навсегда по телефону:

this.requestWindowFeature(Window.FEATURE_NO_TITLE); 

перед setContentView(R.layout.x) в классе деятельности.

Чтобы сделать приложение в полноэкранном режиме, вы можете сделать:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 

Снова поставить выше код перед методом setContentView.

И убедитесь, что если вы это делаете, вы должны расширить свой класс деятельности на Activity, а не AppCompatActivity или любой другой класс.

Смежные вопросы