ProgramingTip

ActionBar가없는 Android 활동

bestdevel 2020. 12. 31. 23:36
반응형

ActionBar가없는 Android 활동


나는 Activities내 앱 이 다르며 모든 앱에서 Action Bar. 제거하는 방법을 수 없습니다. 나는 그것을 적용 할 속성을 더블 고 노력 main_activity.xml했지만 지금까지 아무것도 없었습니다. 누군가 제발 도와 줄 수 있습니까?


하하, 나도 그 시점에 갇혀 있었기 때문에 당신을 나를 위해 일한 해결책으로 도울 수있어서 기쁩니다 :)

당신이 원하는 것은 / styles.xml의 새로운 스타일을 정의하는 것입니다.

<resources>
    <style name = "AppTheme" parent = "android:Theme.Holo.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>

    <style name = "NoActionBar" parent = "@android:style/Theme.Holo.Light">
        <item name = "android:windowActionBar">false</item>
        <item name = "android:windowNoTitle">true</item>
    </style>

</resources>

NoActionBar 스타일만이 당신에게 흥미 진진합니다. 마지막으로 AndroidManifest.xml에서 애플리케이션의 테마로 설정해야 다음과 같이 시청합니다.

<application
    android:allowBackup = "true"
    android:icon = "@drawable/ic_launcher"
    android:label = "@string/app_name"
    android:theme = "@style/NoActionBar"   <!--This is the important line-->
    >
    <activity
    [...]

도움이되지 않았 으면 알려주세요.


이를 수행하는 방법에는 여러 가지가 있습니다.

1) Android Manifest에서 테마 변경

애플리케이션 요소 아래에 테마 태그가 있습니다. 이것으로 교체하십시오-

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

AppCompat를 사용하는 경우 @android:style/Theme.AppCompat.NoActionBar.

이 모든 활동의 테마를 설정합니다. 특정 활동에 작업 표시 줄이 필요하지 않은 경우 활동 컨테이너에 테마를 설정합니다.

<activity android:theme="@android:style/Theme.NoTitleBar" ...>

android:theme="@android:style/Theme.NoTitleBar"스타일에서 테마를 설정 하고 나중에 사용할 수도 있습니다.


2) 사용자 지정 테마 만들기

추가하십시오 res/values/styles.xml

<style name="NoActionBar" parent="@android:style/Theme.Holo.Light">
     <item name="windowActionBar">false</item>
     <item name="android:windowNoTitle">true</item>
</style>

그런 다음 Manifest에서 활동 테마로 설정하십시오.

<activity android:theme="@style/NoActionBar" ... />

3) 액션 바를 동적으로 제거

에서이 코드를 넣어 onCreate방법을 내용보기를 설정하기 전에 -

getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();

지원 라이브러리를 사용하는 경우 getSupportActionBar().


모든 사람이 ActionBar를 숨기는 이전 방법을 게시하고 점을 고려하면 AppCompat 지원 라이브러리의 스타일 내에서이를 구현하는 적절한 방법이 있습니다. 아직하지 않았다면 앞으로 나아가는 것이 좋습니다.

ActionBar 제거하기

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>

appcompat 라이브러리를 사용하는 경우 전체 화면으로 만들거나 레이아웃 내 도구 모음에 구현을 시작하기 위해 ActionBar를 숨기는 가장 권장되는 방법입니다.

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Your Toolbar Color-->
    <item name="colorPrimary">@color/primary</item>

    <!-- colorPrimaryDark is used for the status bar -->
    <item name="colorPrimaryDark">@color/primary_dark</item>

    <!-- colorAccent is used as the default value for colorControlActivated,
     which is used to tint widgets -->
    <item name="colorAccent">@color/accent</item>

    <!-- You can also set colorControlNormal, colorControlActivated
     colorControlHighlight, and colorSwitchThumbNormal. -->
</style>

그런 다음 도구 모음 색상을 변경 비용

<android.support.v7.widget.Toolbar
    android:id=”@+id/my_awesome_toolbar”
    android:layout_height=”wrap_content”
    android:layout_width=”match_parent”
    android:minHeight=”?attr/actionBarSize”
    android:background=”?attr/primary” />

마지막 참고 : 액티비티 클래스는 AppCompatActivity를 확장해야합니다.

public class MainActivity extends AppCompatActivity {

<!--Activity Items -->

}

을 사용하는 경우 다음과 같이 AppCompat활동을 선언하십시오 AndroidManifest.xml.

<activity
    android:name=".SomeActivity"
    ...
    android:theme="@style/Theme.AppCompat.Light.NoActionBar" />

Manifest를 추가 액션 바없이 원하는 활동에 theme = "@ style / Theme.AppCompat.Light.NoActionBar"속성을 추가하십시오.

<application
    ...
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar">
        ...
    </activity>
</application>

여기에 설명 된 대로 상속을 ActionBarActivity에서 Activity로 변경할 수도 있습니다 .

최신 정보

여기에 좋은 해결책이 있습니다 .

@Override
protected void onCreate(Bundle savedInstanceState) {
    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
    super.onCreate(savedInstanceState);
    getSupportActionBar().hide();
    setContentView(R.layout.activity_main);
}

가능한 한 간단하게 보여 드리겠습니다.

ANDROID MAINIFEST 파일에서 전체 화면 활동 선언 :

<activity
            android:name=".GameActivity"
            android:label="@string/title_activity_game"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

이제 Android 스튜디오에서 (사용하는 경우) 디자이너에서 Activity xml 파일 (예 : activity_game.xml)을 열고 테마 (작은 원이있는 디자이너 클릭 버튼의 휴대폰 위)를 선택한 다음 왼쪽에서 Mainfest Themes를 선택하고 그런 다음 NoTitleBar.Fullscreen.

도움이 되길 바랍니다!


대부분의 활동에 작업 표시 줄이 포함되도록하려면 기본 테마에서 기본 테마를 상속 할 수 있습니다 (기본적으로 Android 스튜디오에서 자동으로 생성됨).

<!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

그런 다음 바없는 활동을위한 특별한 테마를 추가하세요.

<style name="AppTheme.NoTitle" parent="AppTheme">
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="actionBarTheme">@null</item>
    </style>

나를 위해 actionBarTheme@null설정 하는 것이 해결책이었습니다.

마지막으로 매니페스트 파일에서 활동을 설정합니다.

<activity ... android:theme="@style/AppTheme.NoTitle" ... >

res / value / style.xml에서 얻는 기본 스타일

  <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
  </style>

활동 태그에서와 같이 바로 아래에

android:theme="@style/AppTheme.NoActionBar"

styles.xml에서 기본 테마를 찾으십시오.

<!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

그리고 이런 식으로 부모를 변경하십시오.

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

내 경우에는 "Theme.Alert.NoActionBar"라는 이름으로 새 스타일을 만듭니다.

<style name="Theme.Alert.NoActionBar" parent="Theme.AppCompat.Dialog">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
</style>

위 코드와 같이 부모를 "Theme.AppCompat.Dialog"로 설정합니다.

AndoridManifest.xml을 열고 다음과 같이 경고 대화 상자로 표시하려는 활동을 사용자 정의하십시오.

    <activity
        android:excludeFromRecents="true"
        android:theme="@style/Theme.Alert.NoActionBar"
        android:name=".activities.UserLoginActivity" />

내 앱에서 내 사용자 로그인 활동을 경고 대화 상자로 표시하고 싶습니다.이 코드는 내가 사용한 코드입니다. 이것이 당신을 위해 작동하기를 바랍니다 !!!


정말 간단 styles.xml합니다 부모 테마를 Theme.AppCompat.Light.NoActionBar또는로 변경하면 Theme.AppCompat.NoActionbar완료됩니다 .. :)

참조 URL : https://stackoverflow.com/questions/25863676/android-activity-without-actionbar

반응형