android-actionbar 相关问题

ActionBar是Android的窗口功能,可识别应用程序和用户位置,并提供用户操作和导航模式。

android-如何从ActionBar

这是我的应用: 现在我想从我的动作栏中删除应用程序名称... 我想要这样: 我的代码: 这是我的应用: 现在我想从我的动作栏中删除应用程序名称... 我想要这样的: 我的代码: <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:myapp="http://schemas.android.com/apk/res-auto" > <item android:id="@+id/phone" android:title="@string/phone" android:icon="@drawable/phone" myapp:showAsAction="ifRoom" /> <item android:id="@+id/computer" android:title="@string/computer" android:icon="@drawable/computer" myapp:showAsAction="ifRoom" /> </menu> ActionBar actionBar = getActionBar(); actionBar.setDisplayShowTitleEnabled(false); actionBar.setDisplayShowHomeEnabled(false); 或您只需致电actionbar.setTitle("") 如果您想隐藏它,请使用此代码 getSupportActionBar().setDisplayShowTitleEnabled(false) 或如果要更改名称,请使用此 getSupportActionBar().setTitle("type yor title here"); 我已经看到了有关位置等的一些问题。这是完整的解决方案。在OnCreate();中使用它 setContentView(R.layout.activity_main); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); // Set title to false AFTER toolbar has been set try { getSupportActionBar().setDisplayShowTitleEnabled(false); } catch (NullPointerException e){} callSETDISPLAYSHOWHOMEENABLED()和SETDISPLAYSHOWTITELEENABLED() 对于Android 4.2.1编辑默认主题noAtionnbar,然后在mainActivity.java file中添加此代码 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (getSupportActionBar() != null) { getSupportActionBar().hide(); } } 您可以尝试setTitle("")。如果您使用的是ActionBar或ToolBar,请致电bar.setTitle("")或: bar.setDisplayShowTitleEnabled(false); bar.setDisplayShowHomeEnabled(false); 仅写这几: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); getSupportActionBar().hide(); setContentView(R.layout.activity_main); } 现在您可以将其设置在OnCreate中 supportActionBar?.hide()

回答 8 投票 0

移民ActionBarsherlock到版本4.0.2(来自3.5)

我需要在运行时添加一些项目。我这样做:

回答 1 投票 0

Android 15 中的 Actionbar 与 Activity 内容重叠

我没有在 XML 文件中定义任何工具栏,而是使用主题中定义的默认 ActionBar: <p>我没有在 XML 文件中定义任何工具栏,而是使用主题中定义的默认 ActionBar:</p> <pre><code>&lt;style name=&#34;AppBaseTheme&#34; parent=&#34;@style/Theme.AppCompat.DayNight.DarkActionBar&#34;&gt; &lt;item name=&#34;colorAccent&#34;&gt;@color/secondary&lt;/item&gt; &lt;item name=&#34;android:actionBarStyle&#34;&gt;@style/AppBaseTheme.ActionBarStyle&lt;/item&gt; &lt;item name=&#34;actionBarStyle&#34;&gt;@style/AppBaseTheme.ActionBarStyle&lt;/item&gt; &lt;item name=&#34;android:textViewStyle&#34;&gt;@style/RobotoTextViewStyle&lt;/item&gt; &lt;item name=&#34;android:buttonStyle&#34;&gt;@style/RobotoButtonStyle&lt;/item&gt; &lt;item name=&#34;android:windowContentOverlay&#34;&gt;@null&lt;/item&gt; &lt;/style&gt; </code></pre> <p>在 Android 14 及之前版本中没有问题,但在 Android 15 中,Activity 内容全屏显示,并且 ActionBar 与 Activity 内容重叠。</p> <p>可以阻止它,然后在 Android 15 中具有与我以前版本中相同的行为吗?</p> <p>谢谢</p> </question> <answer tick="false" vote="0"> <p>我只是为一个应用程序这样做的,基本上分为三个步骤: <em>注意:未处理旋转,但通过一些调整可能可以实现</em></p> <ol> <li>设置 <pre><code>android:fitsSystemWindows=&#34;true&#34;</code></pre> XML 布局根。这修复了重叠,但在系统区域留下了相当难看的半透明条。接下来的两个步骤是解决这个问题。</li> <li>在 XML 布局中或以编程方式在代码中为根视图设置背景图像或可绘制对象,以便为状态栏区域着色。</li> <li>设置 活动中的 <pre><code>getWindow().setNavigationBarContrastEnforced(false)</code></pre> - 如果需要,可删除导航按钮区域下的阴影。</li> </ol> <p>对于 2 和 3,我制作了一个自定义可绘制类(作为可以根据要求进行修改的起点):</p> <pre><code>import android.app.Activity; import android.graphics.Canvas; import android.graphics.ColorFilter; import android.graphics.Paint; import android.graphics.PixelFormat; import android.graphics.drawable.Drawable; import android.os.Build; import android.util.DisplayMetrics; import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; public class CustomBackground extends Drawable { static public void setDecorBackground(Activity activity) { if (android.os.Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.VANILLA_ICE_CREAM) { ViewGroup viewGroup = (ViewGroup) ((ViewGroup) activity .findViewById(android.R.id.content)).getChildAt(0); //if required activity.getWindow().setNavigationBarContrastEnforced(false); ViewCompat.setOnApplyWindowInsetsListener(viewGroup, (v, windowInsets) -&gt; { Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); v.setBackground(CustomBackground.instanceOf(activity, insets)); //Required for the rest of the layout to remain aligned v.onApplyWindowInsets(windowInsets.toWindowInsets()); return WindowInsetsCompat.CONSUMED; }); } } //Reusing a static instance since the dimensions //and color don&#39;t change in my use case, with no rotation private static CustomBackground standardInstance; private static CustomBackground instanceOf(Activity activity, Insets insets) { if (standardInstance == null) { DisplayMetrics m = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(m); standardInstance = new CustomBackground(m.widthPixels, m.heightPixels, activity.getColor(R.color.colorPrimary), insets); // Assuming R.color.colorPrimary is the available and the intended color for the status area } return standardInstance; } private final int width; private final int height; private final int color; private final Insets insets; private CustomBackground(int width, int height, int color, Insets insets) { this.width = width; this.height = height; this.color = color; this.insets = insets; } @Override public void draw(@NonNull Canvas canvas) { Paint paint = new Paint(); paint.setColor(color); if (insets.top&gt;0) { canvas.drawRect(0, 0, width, insets.top+5, paint); } // For additional sides /*if (insets.left&gt;0) { canvas.drawRect(0, 0, insets.left, height, paint); } if (insets.bottom&gt;0) { canvas.drawRect(0, height-insets.bottom, width, height, paint); } if (insets.right&gt;0) { canvas.drawRect(width-insets.right, 0, width, height, paint); }*/ } @Override public void setAlpha(int alpha) { } @Override public int getIntrinsicWidth() { return width; } @Override public int getIntrinsicHeight() { return height; } @Override public void setColorFilter(@Nullable ColorFilter colorFilter) { } @Override public int getOpacity() { return PixelFormat.TRANSLUCENT; } } </code></pre> <p>要在活动中使用它,请在 onCreate Zd 中调用<pre><code>CustomBackground.setDecorBackground(this)</code></pre></p> </answer> </body></html>

回答 0 投票 0

Android 菜单背景黑色,带有 Theme.AppCompat?

由于我的应用程序中的某些原因,当使用“Theme.AppCompat”作为我的样式时,它使我的菜单黑色文本(因为我想要黑色文本而设置)在深灰色背景上,如下所示: 我试过了

回答 7 投票 0

工具栏中的自定义布局

最近我从旧的ActionBar迁移到新的Toolbar。 我有一个自定义活动(实际上是我的主要活动中的一个片段),其中我允许用户单击工具栏中的图标,...

回答 1 投票 0

菜单和操作栏未出现在某些设备上

我的应用程序基于 FragmentActivity,使用 ActionBar,但它是否显示取决于它运行的设备。 使用在 Android 13 或 14 下运行的 Android Studio 模拟器,操作...

回答 1 投票 0

Android 工具栏覆盖内容

我正在使用新工具栏并将其设置为 supportActionBar。 我的问题是它覆盖了我的内容。 这是我用来设置工具栏的代码。 公共无效setupNavBar(){

回答 3 投票 0

Android 菜单项可见性在运行时发生变化

我试图在正在运行的活动的后台执行任务时隐藏操作栏菜单项一段时间。 首先在activity的onPrepareOptionsMenu中遇到...

回答 4 投票 0

材质设计透明ActionBar

我想知道是否有人知道如何制作带有透明操作栏的活动, 就像您进入应用程序页面时在新的 Google Play 商店中看到的那样。 我不在乎卷轴...

回答 8 投票 0

如何在jetpack compose中启动屏幕后隐藏操作栏?

我已经按照这篇文章启动屏幕显示了以下所有 API 级别的图标,但没有任何活动。支持 android 12 及以上设备的闪屏。 启动画面工作正常...

回答 1 投票 0

如何完全隐藏Android工具栏中的后退按钮(向上按钮)?

我正在开发一款带有一个 MainActivity 和三个片段的 Android 应用程序。我已成功禁用工具栏中的后退按钮(向上按钮),但它仍然在工具栏中呈现。我想要...

回答 1 投票 0

如何将正确的主题颜色应用于操作栏中的自定义向上指示器?

如何在 supportActionBar.setHomeAsUpIndicator() 中为操作栏应用正确的颜色? 我最终在充气时获得默认图标色调颜色,而不是操作栏色调颜色,

回答 1 投票 0

Android 操作栏可检查菜单项无法正常工作/显示?

所以我试图让我的菜单项显示在操作栏上,使其表现得像一个可检查的菜单选项。第一部分有效,这意味着它是可检查的,当我按下它并在代码中设置 setC...

回答 4 投票 0

工具栏布局与父宽度不匹配

我已经阅读了几个类似的主题,但仍然没有找到这个问题的答案。我有一个自定义的工具栏布局: 我已经阅读了几个类似的主题,但仍然没有找到这个问题的答案。我有一个自定义的工具栏布局: <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:background="#99000000"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar_transparent" android:layout_height="wrap_content" android:layout_width="match_parent" android:fitsSystemWindows="true" android:minHeight="?attr/actionBarSize" app:theme="@style/MyToolbar"> </android.support.v7.widget.Toolbar> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@android:color/white" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_centerInParent="true" android:id="@+id/toolbar_title" /> </RelativeLayout> 这是我的活动代码: toolbar = (Toolbar) findViewById(R.id.toolbar_transparent); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowTitleEnabled(false); 我的工具栏仍然有左右填充,并且不填充父宽度。我尝试过各种解决方案。我的代码有什么问题吗? 问题是我需要我的工具栏是半透明的。这就是为什么我在布局 android:background="#99000000" 中使用这一行。我将它应用到整个布局,我的工具栏变得半透明,但它没有填充父级的宽度。但是,如果我将 android:background="#99000000" 这条线不应用到整个布局,而是应用到布局中的工具栏小部件,它会正确填充父级,但会失去透明度。这有帮助吗? 如果填充有问题,您可以尝试设置 contentInset 属性: https://developer.android.com/reference/android/widget/Toolbar.html#attr_android:contentInsetStart 尝试这个布局: 半透明 toolbar <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/general_appbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@null"> <android.support.v7.widget.Toolbar android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="#99000000"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="Login" android:textSize="20sp" /> </android.support.v7.widget.Toolbar> </android.support.design.widget.AppBarLayout> 输出: 要修改工具栏元素,请添加以下属性: app:contentInsetLeft="0dp" app:contentInsetStart="0dp" 示例: <androidx.appcompat.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:contentInsetLeft="0dp" app:contentInsetStart="0dp"> <!--Your Custom Child View--> </androidx.appcompat.widget.Toolbar> contentInsetStart的默认值通常为16dp,但您需要根据您的要求将其明确设置为0dp。

回答 3 投票 0

getSupportActionBar().setTitle() 与工具栏.setTitle()

我知道有两种方法可以在 Android Activity 中设置标题。 假设我已经有以下代码...... @覆盖 protected void onCreate(Bundle savingInstanceState) { 是...

回答 3 投票 0

操作栏未隐藏

所以我正在制作一个移动应用程序,在我的主菜单中,在多次尝试隐藏它之后,操作栏/标题栏仍然显示。 我尝试更改主题女巫不起作用,我尝试将其隐藏在

回答 1 投票 0

如何显示android操作栏标题而不发生截断

我有一个具有相当长标题的应用程序(例如我的长标题应用程序)。 我正在使用 ActionBar 并注意到应用程序标题不断被截断(例如我的长标题 A...)。 即使 2 ...

回答 5 投票 0

更新滚动条上的填充时性能缓慢(折叠顶部栏)

我有一个带有 LargeTopBar 和nestedScroll 的脚手架,用于折叠内容滚动上的栏,一切在模拟器上看起来都不错,但在真实设备上性能非常滞后(在发布模式下运行...

回答 1 投票 0

Spinner:当所选项目保持不变时,不会调用 onItemSelected

我的 Spinner 有一个 OnItemSelectedListener,但当所选项目与前一个项目相同时,不会调用它。显然 OnClickListener 不是 Spinner 的选项。 我需要...

回答 12 投票 0

如何在 Jetpack Compose 中对 ActionBar 下的内容应用模糊效果?

到目前为止,我有一个简单的支架,带有透明的 ActionBar 和 StatusBar,我的内容在两个栏下都能很好地滚动,包括将顶部颜色更改为透明黑色的滚动行为...

回答 1 投票 0

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.