【发布时间】:2016-08-18 21:43:28
【问题描述】:
我希望能够调整 actionMode 的大小,或者至少有一个与工具栏大小相同的 actionMode。
我有一个纵向和横向尺寸固定的工具栏。我使用 56dp(移动纵向工具栏值)作为两者的值。
我的工具栏没问题。问题是,在方向更改期间,我的 actionMode 从 android ?attr/actionBarSize 获取默认值,因此在横向中,我最终得到的 actionMode 小于工具栏。
普通动作模式代码
if (actionMode == null) {
actionMode = ((AppCompatActivity)getActivity()).startSupportActionMode(actionModeCallback);
}
我尝试在 onConfigurationChanged 中更改 actionMode 的大小,但没有成功。这是更改工具栏大小的示例。显然没有办法对 actionMode 做同样的事情。有什么建议么?谢谢
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE || newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
Toolbar toolbar = ((MainActivity)getActivity()).getToolbar(); //my custom method to get the toolbar
if (toolbar != null) {
int toolbarHeight = (int)getResources().getDimension(R.dimen.toolbar_height);
toolbar.setMinimumHeight(toolbarHeight);
ViewGroup.LayoutParams lp = toolbar.getLayoutParams();
lp.height = toolbarHeight;
toolbar.setLayoutParams(lp);
}
}
}
【问题讨论】:
标签: android android-toolbar landscape-portrait android-actionmode