添加获取状态栏高度
This commit is contained in:
parent
076139cb1f
commit
dcc182827c
@ -1,6 +1,7 @@
|
||||
package com.hi.music.player.ui.activity;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import com.google.android.material.tabs.TabLayoutMediator;
|
||||
@ -45,6 +46,13 @@ public class HomeActivity extends BaseActivity<ActivityHomeBinding> {
|
||||
}
|
||||
|
||||
public void initView() {
|
||||
|
||||
int statusBarHeight = getStatusBarHeight();
|
||||
int navigationBarHeight = getNavigationBarHeight();
|
||||
|
||||
View root = vb.getRoot();
|
||||
root.setPadding(0,statusBarHeight,0,0);
|
||||
|
||||
HomeViewPagerAdapter adapter = new HomeViewPagerAdapter(this);
|
||||
vb.homeViewPager.setAdapter(adapter);
|
||||
|
||||
@ -86,5 +94,25 @@ public class HomeActivity extends BaseActivity<ActivityHomeBinding> {
|
||||
int position = tab.getPosition();
|
||||
tabBinding.homeIcon.setImageResource(isSelected ? selectedIcons[position] : defaultIcons[position]);
|
||||
}
|
||||
|
||||
// 获取状态栏高度的方法
|
||||
public int getStatusBarHeight() {
|
||||
int statusBarHeight = 0;
|
||||
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
|
||||
if (resourceId > 0) {
|
||||
statusBarHeight = getResources().getDimensionPixelSize(resourceId);
|
||||
}
|
||||
return statusBarHeight;
|
||||
}
|
||||
|
||||
// 获取导航栏高度的方法
|
||||
public int getNavigationBarHeight() {
|
||||
int navigationBarHeight = 0;
|
||||
int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android");
|
||||
if (resourceId > 0) {
|
||||
navigationBarHeight = getResources().getDimensionPixelSize(resourceId);
|
||||
}
|
||||
return navigationBarHeight;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -56,7 +56,7 @@
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/ic_launcher_foreground" />
|
||||
android:src="@drawable/ic_launcher_background" />
|
||||
</FrameLayout>
|
||||
|
||||
<!-- 标题 -->
|
||||
@ -104,7 +104,7 @@
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/ic_launcher_foreground" />
|
||||
android:src="@drawable/ic_launcher_background" />
|
||||
</FrameLayout>
|
||||
|
||||
<!-- 标题 -->
|
||||
|
||||
Loading…
Reference in New Issue
Block a user