2017-10-13 120 views
0

出於某種原因,我的MainActivity工具欄再次出現(在我從應用程序中刪除所有工具欄後),灰色(應用程序的其餘部分爲藍色)。我想在xml中將其刪除,佈局主題與應用程序的其餘部分完全相同。這就是爲什麼我不確定有什麼問題,並且無法在網上找到任何解決方案。從特定活動隱藏工具欄

風格:

<style id="checkBoxStyle" name="checkBoxStyle" parent="Base.Theme.AppCompat"> 
    <item name="colorAccent">@color/colorPrimary</item> 
    <item name="android:textColorSecondary">#dc302e2e</item> 
    <item name="android:editTextColor">#000000</item> 
</style> 

MainActivity佈局:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 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:background="@drawable/weakbeach" 
    android:theme="@style/checkBoxStyle" 
    tools:context="com.example.itay.newfrindlyalarm.MainActivity" 
    android:focusableInTouchMode="true"> 


    <Button 
     android:id="@+id/buttonSetting" 
     android:layout_width="192dp" 
     android:layout_height="wrap_content" 
     android:background="#1a6ca3" 
     android:text="Settings" 
     android:textAllCaps="true" 
     android:textColor="#ffffff" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginBottom="32dp" 
     android:layout_marginLeft="8dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     android:layout_marginRight="8dp" 
     app:layout_constraintRight_toRightOf="parent" 
     android:layout_marginStart="8dp" 
     android:layout_marginEnd="8dp" /> 

    <Button 
     android:id="@+id/button_add_alarm" 
     android:layout_width="270dp" 
     android:layout_height="wrap_content" 
     android:background="@color/ligthSec" 
     android:text="Add new Alarm:" 
     android:textAllCaps="true" 
     android:textColor="#ffffff" 
     android:textSize="20dp" 
     app:layout_constraintLeft_toLeftOf="@+id/buttonSetting" 
     app:layout_constraintRight_toRightOf="@+id/buttonSetting" 
     app:layout_constraintTop_toBottomOf="@+id/alarmMessage" /> 

    <TimePicker 
     android:id="@+id/alarmTimePicker" 
     android:layout_width="200dp" 
     android:layout_height="144dp" 
     android:layout_marginBottom="8dp" 
     android:layout_marginEnd="8dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginStart="8dp" 
     android:timePickerMode="spinner" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintVertical_bias="0.00999999"></TimePicker> 

    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="65dp" 
     android:layout_height="75dp" 
     android:layout_marginEnd="16dp" 
     android:layout_marginRight="16dp" 
     app:layout_constraintBottom_toTopOf="@+id/checkBoxDay4" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     app:srcCompat="@drawable/alarmclock" /> 


    <CheckBox 
     android:id="@+id/checkBoxDay2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginEnd="8dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginStart="8dp" 
     android:button="@null" 
     android:drawableRight="?android:attr/listChoiceIndicatorMultiple" 
     android:text="M" 
     app:layout_constraintBaseline_toBaselineOf="@+id/checkBoxDay3" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toLeftOf="@+id/checkBoxDay4" /> 

    <CheckBox 
     android:id="@+id/checkBoxDay7" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginEnd="8dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginStart="8dp" 
     android:button="@null" 
     android:drawableRight="?android:attr/listChoiceIndicatorMultiple" 
     android:text="S" 
     app:layout_constraintBaseline_toBaselineOf="@+id/checkBoxDay6" 
     app:layout_constraintLeft_toRightOf="@+id/checkBoxDay6" 
     app:layout_constraintRight_toRightOf="parent" /> 

    <CheckBox 
     android:id="@+id/checkBoxDay1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginEnd="8dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginStart="8dp" 
     android:button="@null" 
     android:drawableRight="?android:attr/listChoiceIndicatorMultiple" 
     android:text="S" 
     app:layout_constraintBaseline_toBaselineOf="@+id/checkBoxDay2" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toLeftOf="@+id/checkBoxDay2" /> 

    <CheckBox 
     android:id="@+id/checkBoxDay6" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginEnd="8dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginStart="8dp" 
     android:button="@null" 
     android:drawableRight="?android:attr/listChoiceIndicatorMultiple" 
     android:text="F" 
     app:layout_constraintBaseline_toBaselineOf="@+id/checkBoxDay5" 
     app:layout_constraintLeft_toRightOf="@+id/checkBoxDay4" 
     app:layout_constraintRight_toRightOf="parent" /> 

    <CheckBox 
     android:id="@+id/checkBoxDay5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginEnd="8dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginStart="8dp" 
     android:button="@null" 
     android:drawableRight="?android:attr/listChoiceIndicatorMultiple" 
     android:text="T" 
     app:layout_constraintBaseline_toBaselineOf="@+id/checkBoxDay4" 
     app:layout_constraintLeft_toRightOf="@+id/checkBoxDay4" 
     app:layout_constraintRight_toLeftOf="@+id/checkBoxDay6" /> 

    <CheckBox 
     android:id="@+id/checkBoxDay4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:button="@null" 
     android:checked="false" 
     android:drawableRight="?android:attr/listChoiceIndicatorMultiple" 
     android:text="W" 
     app:layout_constraintHorizontal_bias="0.56" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/alarmTimePicker" /> 

    <CheckBox 
     android:id="@+id/checkBoxDay3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginEnd="8dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginStart="8dp" 
     android:button="@null" 
     android:drawableRight="?android:attr/listChoiceIndicatorMultiple" 
     android:text="T" 
     app:layout_constraintBaseline_toBaselineOf="@+id/checkBoxDay4" 
     app:layout_constraintLeft_toRightOf="@+id/checkBoxDay2" 
     app:layout_constraintRight_toLeftOf="@+id/checkBoxDay4" /> 


    <ToggleButton 
     android:id="@+id/repeateButton" 
     android:layout_width="88dp" 
     android:layout_height="83dp" 
     android:layout_marginBottom="8dp" 
     android:layout_marginEnd="8dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginStart="8dp" 
     android:layout_marginTop="8dp" 
     android:background="@null" 
     android:gravity="bottom" 
     app:layout_constraintBottom_toTopOf="@+id/checkBoxDay1" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toLeftOf="@+id/alarmTimePicker" 
     app:layout_constraintTop_toTopOf="parent" 
     android:drawable="@drawable/chenge_image_repeat" 
     app:layout_constraintHorizontal_bias="0.0" 
     app:layout_constraintVertical_bias="0.122" /> 

    <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     app:srcCompat="@drawable/chenge_image_repeat" 
     app:layout_constraintTop_toTopOf="parent" 
     android:layout_marginTop="16dp" 
     app:layout_constraintRight_toRightOf="@+id/repeateButton" 
     app:layout_constraintLeft_toLeftOf="@+id/repeateButton" /> 

    <EditText 
     android:id="@+id/alarmMessage" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:maxLength="32" 
     android:inputType="textPersonName" 
     android:text="" 
     android:hint="Enter Your Alarm message here" 
     android:textColorHint="#767373" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/checkBoxDay4" /> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/alarm_list" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_marginBottom="8dp" 
     android:layout_marginEnd="8dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginStart="8dp" 
     app:layout_constraintBottom_toTopOf="@+id/buttonSetting" 
     app:layout_constraintHorizontal_bias="0.0" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/button_add_alarm" 
     app:layout_constraintVertical_bias="0.0"> 


    </android.support.v7.widget.RecyclerView> 

    <Spinner 
     android:id="@+id/ringtonesSpinner" 
     android:layout_width="69dp" 
     android:layout_height="wrap_content" 
     tools:layout_editor_absoluteX="8dp" 
     tools:layout_editor_absoluteY="194dp" /><![CDATA[ 

     ; 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     tools:layout_editor_absoluteY="32dp" /> 



]]> 
</android.support.constraint.ConstraintLayout> 

另一個活動佈局(一個多數民衆贊成在工具欄被刪除,顏色爲藍色):

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 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:background="@drawable/cute_dog_n_pinguin" 
    android:layout_width="match_parent" 
    android:theme="@style/checkBoxStyle" 
    android:layout_height="match_parent" 
    tools:context="com.example.itay.newfrindlyalarm.AlarmSettings"> 


    <TextView 
     android:id="@+id/textView_snozee_settings" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Snooze Settings:" 
     android:textColor="@color/greySettings" 
     android:textSize="20sp" 
     android:textStyle="bold" 
     android:layout_marginStart="8dp" 
     app:layout_constraintTop_toTopOf="parent" 
     android:layout_marginTop="32dp" 
     android:layout_marginLeft="8dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     android:layout_marginRight="8dp" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintHorizontal_bias="0.15" 
     android:layout_marginEnd="8dp" /> 

    <Switch 
     android:id="@+id/switch_snooze" 
     android:checked="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="snooze on: " 
     android:textSize="15sp" 
     android:textStyle="bold" 
     android:textColor="#000000" 
     android:layout_marginTop="16dp" 
     app:layout_constraintTop_toBottomOf="@+id/textView_snozee_settings" 
     android:layout_marginLeft="24dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     android:layout_marginStart="24dp" /> 

    <TextView 
     android:id="@+id/textView_snooze_time" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Snooze time:" 
     android:textStyle="bold" 
     android:textSize="15sp" 
     android:textColor="#000000" 
     android:layout_marginTop="16dp" 
     app:layout_constraintTop_toBottomOf="@+id/switch_snooze" 
     android:layout_marginLeft="24dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     android:layout_marginStart="24dp" /> 

    <CheckBox 
     android:id="@+id/checkBox_5" 
     android:checked="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="5" 
     android:textColor="#000000" 
     app:layout_constraintLeft_toRightOf="@+id/checkBox_3" 
     android:layout_marginLeft="12dp" 
     android:layout_marginStart="12dp" 
     app:layout_constraintBottom_toBottomOf="@+id/checkBox_3" 
     app:layout_constraintTop_toTopOf="@+id/checkBox_3" /> 

    <CheckBox 
     android:id="@+id/checkBox_7" 
     android:checked="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="7" 
     android:textColor="#000000" 
     app:layout_constraintLeft_toRightOf="@+id/checkBox_5" 
     android:layout_marginLeft="12dp" 
     android:layout_marginStart="12dp" 
     app:layout_constraintBottom_toBottomOf="@+id/checkBox_5" 
     app:layout_constraintTop_toTopOf="@+id/checkBox_5" /> 

    <CheckBox 
     android:id="@+id/checkBox20" 
     android:checked="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="20" 
     android:textColor="#000000" 
     app:layout_constraintLeft_toLeftOf="@+id/checkBox_7" 
     app:layout_constraintBottom_toBottomOf="@+id/checkBox15" 
     app:layout_constraintTop_toTopOf="@+id/checkBox15" /> 

    <CheckBox 
     android:id="@+id/checkBox15" 
     android:checked="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="15" 
     android:textColor="#000000" 
     app:layout_constraintLeft_toLeftOf="@+id/checkBox_5" 
     app:layout_constraintBottom_toBottomOf="@+id/checkBox10" 
     app:layout_constraintTop_toTopOf="@+id/checkBox10" /> 

    <CheckBox 
     android:id="@+id/checkBox10" 
     android:checked="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="12dp" 
     android:layout_marginTop="15dp" 
     android:text="10" 
     android:textColor="#000000" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/checkBox_3" 
     android:layout_marginStart="12dp" /> 

    <CheckBox 
     android:id="@+id/checkBox_3" 
     android:checked="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="3" 
     android:textColor="#000000" 
     android:layout_marginTop="16dp" 
     app:layout_constraintTop_toBottomOf="@+id/textView_snooze_time" 
     app:layout_constraintLeft_toLeftOf="@+id/checkBox10" /> 
    <Button 
     android:id="@+id/buttonRingtone" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Set Ringtone" 
     android:textColor="#d4d4d4" 
     android:layout_marginLeft="24dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     android:layout_marginTop="16dp" 
     app:layout_constraintTop_toBottomOf="@+id/checkBox15" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginBottom="8dp" 
     app:layout_constraintVertical_bias="0.00999999" /> 

</android.support.constraint.ConstraintLayout> 

我確保解決方案很簡單,我只是浪費了3個小時試圖找出答案。非常感謝!

編輯: 我加了一些圖片: MainActivity

How the Toolbar should be

+0

你能發佈MainActivity的整體佈局?或者是全部? –

+0

我雖然其餘的是無關的,我的壞。我會發布一切,它有點長 –

+0

也許你應該在你的樣式中擴展Theme.AppCompat.NoActionBar? – Frank

回答

0

感謝你的幫助,但問題是在清單。 我需要選擇清單中的活動的權利的主題,而不是在XML文件 (相關清單部分):

<activity android:name=".MainActivity" 
     android:theme="@style/AppTheme.NoActionBar"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 

    </activity> 
2
try this one 

<style name="AppTheme.FullScreen"> 
    <item name="windowNoTitle">true</item> 
    <item name="windowActionBar">false</item> 
    <item name="android:windowFullscreen">true</item> 
    <item name="android:windowContentOverlay">@null</item> 
</style>