代码中获取

  • getActionbar().getHeight() 这个方法在onCreate中是获取不到高度的,平常使用还可以
  • 第二种,通过主题数据获取高度
    /**
       * 获取ActionBar 高度
       * @param context
       * @return
       */
      public static int getActionBarHeight(Context context){
          TypedValue tv = new TypedValue();
          if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize,tv,true)){
              return  TypedValue.complexToDimensionPixelSize(tv.data,
                      context.getResources().getDisplayMetrics());
          }
          return 0;
      }

     

xml中使用

android:paddingTop="?android:attr/actionBarSize"

 

相关文章:

  • 2022-12-23
  • 2022-02-03
  • 2022-12-23
  • 2021-11-18
  • 2021-12-25
  • 2022-01-08
  • 2021-12-12
  • 2022-12-23
猜你喜欢
  • 2021-05-16
  • 2022-12-23
  • 2021-11-30
  • 2021-11-30
  • 2021-12-25
  • 2021-08-30
相关资源
相似解决方案