2015-10-21 3 views
0

Я только что скачал Android Studio, и в большинстве случаев у вас есть синяя панель действий и кнопка Pink с иконкой конверта по умолчанию, и я не могу понять, как ее удалить.ActionBar не удалит

Вещи, которые я пробовал являются:

  1. Изменение темы приложения для xxxxx.Light/Dark.NoActionBar

  2. Измененные значения величин> styles.xml

Самое большее, что я могу сделать, это сделать его серым, но он никогда не удалит его. Заметьте, что я ничего не изменил к файлу.

content_main.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" 
    xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" 
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:showIn="@layout/activity_main" tools:context=".MainActivity"> 

    <TextView android:text="Hello World!" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
</RelativeLayout> 

MainActivity.java

public class MainActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 

     FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 
     fab.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 
         .setAction("Action", null).show(); 
      } 
     }); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.menu_main, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 

     //noinspection SimplifiableIfStatement 
     if (id == R.id.action_settings) { 
      return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 
} 

значения \ styles.xml

<resources> 

    <!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
     <!-- Customize your theme here. --> 
    </style> 
    <style name="AppTheme.NoActionBar"> 
     <item name="windowActionBar">false</item> 
     <item name="windowNoTitle">true</item> 
    </style> 
    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> 
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> 

</resources> 

значения \ стили (v21)

<resources>> 
    <style name="AppTheme.NoActionBar"> 
     <item name="windowActionBar">false</item> 
     <item name="windowNoTitle">true</item> 
     <item name="android:windowDrawsSystemBarBackgrounds">true</item> 
     <item name="android:statusBarColor">@android:color/transparent</item> 
    </style> 
</resources> 
+0

см. Мой ответ ниже, он находится в файле, где размещается content_main, который вам нужно удалить AppBarLayout и панель инструментов, так как вы можете видеть, что этот content_main.xml завернут в тег include в этом макете. –

ответ

1

В главном файле макета, вы увидите AppBarLayout обертывание Toolbar, если вы не хотите ActionBar, это должно быть удалено, поскольку они являются новые виджеты, которые замещают, что раньше было известно как ActionBar

здесь является activity_main.xml, где вам необходимо удалить

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
     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:fitsSystemWindows="true" 
     tools:context=".MainActivity"> 
    <!-- REMOVE THIS AppBarLayout to remove the Toolbar--> 
    <android.support.design.widget.AppBarLayout 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent"   
      android:theme="@style/AppTheme.AppBarOverlay"> 
    <android.support.v7.widget.Toolbar android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 

     </android.support.design.widget.AppBarLayout> 

     <include layout="@layout/content_main" /> 

    <android.support.design.widget.FloatingActionButton android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@android:drawable/ic_dialog_email" /> 

</android.support.design.widget.CoordinatorLayout> 

, то в вашей деятельности падение линии:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
setSupportActionBar(toolbar); 
0

Попробуйте добавить это в теге приложения в манифесте:

android:theme="@android:style/Theme.NoTitleBar" 
+0

Что этот комментарий пытается сказать? –

0

попробовать это, это поможет вам

<activity 
      android:name=".MainActivity" 
      android:label="@string/app_name" 
      android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen"> 
0

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

<android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay"/> 


    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@android:drawable/ic_dialog_email"/> 

Если вам необходимо предотвратить это происходит в следующих проектах, которые вы создаете, выберите Empty Activity вместо Blank деятельности