簡體   English   中英

Android如何獲取動作條的寬度

[英]Android how to get the width of actionbar

我需要獲取操作欄的寬度,我已經看到很多東西要獲取高度,而不是寬度? 有人可以幫忙嗎? 參見下面的代碼:

if(Build.VERSION.SDK_INT >= 11.0){
                            TypedValue tv = new TypedValue();
                            ((Activity) context).getTheme().obtainStyledAttributes(
                                    new int[] { android.R.attr.actionBarSize });
                            ((Activity) context).getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true);
                            actionBarWidth = ((Activity) context).getResources().getDimensionPixelSize(tv.resourceId);
                        }

您可以使用LayoutParams。 布局參數允許您獲取和設置任何與View繼承的對象有關的布局參數,例如高度,寬度等。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM