gpt4 book ai didi

android - 如何在 Android 中的操作栏上方显示自定义 View

转载 作者:行者123 更新时间:2023-11-29 16:32:43 29 4
gpt4 key购买 nike

Google 音乐应用程序的屏幕截图:

enter image description here

我有这两个问题:

1.如何调用这样的元素以及如何实现这样的东西?

2.它们怎么能在action bar上面呢?

最佳答案

这里有一个简单的方法来实现这一点。 ActionBar 将其布局保存在 ActionBarContainer 类中,它只是继承 FrameLayout。因此,为了在 ActionBar 上显示某些内容,您需要获取对 ActionBarContaine 的引用r 并将您的自己的自定义 View 添加到其中。这是代码

// first get the id of Action bar container    
int actionbarContainerViewID = getResources().getIdentifier("action_bar_container", "id", "android");
FrameLayout actionBarContainer = (FrameLayout)findViewById(actionbarContainerViewID);

// bring the layout inflator to inflate your custom layout
LayoutInflater mInflater = getLayoutInflater();
View customView = mInflater.inflate(R.layout.yourCustomDesign, null);
actionBarContainer.addView(customView);

您不需要任何特殊的方式就可以将其置于顶部!随心所欲地设计,它就会在顶部!

关于android - 如何在 Android 中的操作栏上方显示自定义 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53982681/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com