Android:更改一个片段的应用栏高度并删除文本。

huangapple go评论94阅读模式
英文:

Android: Change App bar height of one fragment and delete text

问题

我想要更改特定的fragment_layout的应用程序栏。我想将高度从默认值"56dp"更改为"96dp"以适应我的公司徽标。我还想删除默认文本。

不幸的是,我在互联网上没有找到任何关于此的参考,或者可能是我忽略了它。

我将非常感谢任何帮助。

编辑:我知道如何更改整个应用程序的应用程序栏高度,但这不是这里的问题 Android:更改一个片段的应用栏高度并删除文本。

英文:

I would like to change the app bar of a certain fragment_layout. I would like to change the height from the default value "56dp" to "96dp" to fit my company logo. I also want to delete the default text.

Unfortunately, I have not found any reference to this on the Internet or have overlooked it.

I would be glad about any help.

EDIT: I know how to change the app bar height of the entire app, but that is not the question here Android:更改一个片段的应用栏高度并删除文本。

答案1

得分: 1

以下是您要翻译的内容:

"Let's have a look to how the toolbar is declared inside a layout.

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:titleTextColor="@color/colorTextMain"
android:background="@color/colorPrimary">

</androidx.appcompat.widget.Toolbar>

Pay attention to attributes android:minHeight and android:layout_height="wrap_content".

MinHeight attribute references itself to ?attr/actionBarSize which has a value of 56dp.

1) To change the toolbar height change android:layout_height.

Example: android:layout_height="300dp"

2) To delete the default text, you will have to find the toolbar from code and use a method. Add this to the class where you setContentView of the layout containing the toolbar.

Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setDisplayShowTitleEnabled(false);

Result:

Android:更改一个片段的应用栏高度并删除文本。

英文:

Let's have a look to how the toolbar is declared inside a layout.

    &lt;androidx.appcompat.widget.Toolbar
        android:id=&quot;@+id/toolbar&quot;
        android:minHeight=&quot;?attr/actionBarSize&quot;
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;wrap_content&quot;
        app:titleTextColor=&quot;@color/colorTextMain&quot;
        android:background=&quot;@color/colorPrimary&quot;&gt;

    &lt;/androidx.appcompat.widget.Toolbar&gt;

Pay attention to attributes android:minHeight and android:layout_height=&quot;wrap_content.

MinHeight attribute references itself to ?attr/actionBarSize which has a value of 56dp.

1) To change the toolbar height change android:layout_height.

Example: android:layout_height=&quot;300dp&quot;

2) To delete the default text, you will have to find the toolbar from code and use a method. Add this to the class where you setContentView of the layout containing the toolbar.

Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setDisplayShowTitleEnabled(false);

Result:

Android:更改一个片段的应用栏高度并删除文本。

huangapple
  • 本文由 发表于 2020年8月14日 17:12:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/63409913.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定