Lut*_*cha 57 java android android-actionbar
我Activities在我的应用程序中有所不同,并且在所有这些应用程序中我都不想要Action Bar.我找不到如何禁用它.我试图找到一个属性来应用它,main_activity.xml但到目前为止我没有找到任何东西.有人可以帮帮我吗?
JRs*_*Rsz 88
哈哈,我刚才也被困在那一点上,所以我很高兴我可以帮你解决问题,至少对我有用:)
你想要做的是在values/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>
Run Code Online (Sandbox Code Playgroud)
只有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
[...]
Run Code Online (Sandbox Code Playgroud)
我希望这有帮助,如果没有,请告诉我.
Con*_*use 70
有多种方法可以做到这一点.
在Application元素下面,您将找到主题标记.用这个替换它 -
android:theme="@android:style/Theme.NoTitleBar"
Run Code Online (Sandbox Code Playgroud)
如果您使用的是AppCompat,请使用@android:style/Theme.AppCompat.NoActionBar.
这将为所有活动设定主题.如果您不需要特定活动中的操作栏,则在活动容器中设置主题,即
<activity android:theme="@android:style/Theme.NoTitleBar" ...>
Run Code Online (Sandbox Code Playgroud)
您也可以android:theme="@android:style/Theme.NoTitleBar"在样式中设置主题并在以后使用它.
添加此内容 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>
Run Code Online (Sandbox Code Playgroud)
然后在Manifest中将其设置为活动的主题:
<activity android:theme="@style/NoActionBar" ... />
Run Code Online (Sandbox Code Playgroud)
在设置内容视图之前将此代码放在onCreate方法中-
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();
Run Code Online (Sandbox Code Playgroud)
如果您使用的是支持库getSupportActionBar().
Eug*_*e H 12
考虑到每个人都在发布隐藏ActionBar的旧方法,这是在AppCompat支持库的样式中实现它的正确方法.如果你还没有,我强烈建议你继续前进.
只需删除ActionBar即可
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
Run Code Online (Sandbox Code Playgroud)
如果您正在使用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>
Run Code Online (Sandbox Code Playgroud)
然后更改工具栏颜色
<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” />
Run Code Online (Sandbox Code Playgroud)
最后一点:您的Activity类应该扩展AppCompatActivity
public class MainActivity extends AppCompatActivity {
<!--Activity Items -->
}
Run Code Online (Sandbox Code Playgroud)
小智 10
您在 res/value/style.xml 中获得的默认样式,例如
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
就像在您的活动标签中一样,
android:theme="@style/AppTheme.NoActionBar"
Run Code Online (Sandbox Code Playgroud)
如果您使用AppCompat,请AndroidManifest.xml按照以下步骤声明您的活动:
<activity
android:name=".SomeActivity"
...
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
Run Code Online (Sandbox Code Playgroud)
小智 7
如果您希望您的大部分活动都有一个操作栏,您可能会从默认主题继承您的基本主题(默认情况下,这是由 Android Studio 自动生成的):
<!-- 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>
Run Code Online (Sandbox Code Playgroud)
然后为您的无酒吧活动添加一个特殊的主题:
<style name="AppTheme.NoTitle" parent="AppTheme">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="actionBarTheme">@null</item>
</style>
Run Code Online (Sandbox Code Playgroud)
对我来说,设置actionBarTheme到@null是解决办法。
最后在清单文件中设置活动:
<activity ... android:theme="@style/AppTheme.NoTitle" ... >
Run Code Online (Sandbox Code Playgroud)
您还可以按照此处所述将继承从 ActionBarActivity 更改为 Activity 。
更新
一个很好的解决方案在这里:
@Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_main);
}
Run Code Online (Sandbox Code Playgroud)
打开清单,然后将属性theme =“ @ style / Theme.AppCompat.Light.NoActionBar”添加到您想要的没有actionbar的活动中:
<application
...
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
...
</activity>
</application>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
108975 次 |
| 最近记录: |