【问题标题】:Remove Toolbar title margin in ActionMode在 ActionMode 中删除工具栏标题边距
【发布时间】:2020-06-03 22:21:27
【问题描述】:

我希望删除导航图标和我的 actionMode 标题之间的空格。由于以下原因,我设法为工具栏删除了它:

<style name="AppTheme" parent="Theme.MaterialComponents.Light">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorPrimary</item>
        <item name="toolbarStyle">@style/cusToolbarStyle</item>
</style>

<style name="cusToolbarStyle" parent="@style/Widget.MaterialComponents.Toolbar">
        <item name="titleMargin">0dp</item>
        <item name="contentInsetStartWithNavigation">0dp</item>
        <item name="contentInsetStart">0dp</item>
        <item name="android:background">@color/white</item>
</style>

但是我无法更改模式操作以删除照片上的空间:

【问题讨论】:

  • 检查一下 toolbar.contentInsetStartWithNavigation = NUMBER 在你的 java/kotlin 代码中使用它。
  • 是toolbar.setContentInsetStartWithNavigation(0);不 ?当我把它放在 onCreate 方法中时它不会改变任何东西
  • @CodingFR 是一样的,@abstractArrow 的代码是 Kotlin。我认为,您可以在最新版本的 Android Studio 中使用LayoutInspector 来找出TextViewid 以及其他属性,例如margin_start。如果您知道id,那么您可以创建TextView 对象并随意使用它的属性。试试看这是否可行。

标签: java android toolbar android-actionmode


【解决方案1】:

好的,这既复杂又困难,但我使用了 LayoutInspector,例如 @cgb_pandey 向我建议的。于是找到了关闭ImageView的系统标识,在onPrepareActionMode方法中加入如下代码:

@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
       AppCompatImageView imageView = findViewById(com.google.android.material.R.id.action_mode_close_button);

       if (imageView != null) {
           LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
           params.setMargins(0, 0, 0, 0);
           imageView.setLayoutParams(params);
       }

       return false;
   }

【讨论】:

  • 那么,这行得通吗?其实我只是注意到我的Toolbar也有很大的差距xD
  • 是的,即使没有优化它也能完美运行;)
猜你喜欢
  • 2016-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-12
  • 1970-01-01
  • 2014-12-26
  • 2015-11-02
  • 1970-01-01
相关资源
最近更新 更多