最佳答案
这是实现此目的的简单方法。 ActionBar 将其布局保留在 ActionBarContainer 类中,该类只是继承自FrameLayout。因此,为了在 ActionBar 上显示某些内容,您需要获取对 ActionBarContaine 的引用并将您自己的自定义 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/