[英]Disable status bar android
嗨,我想禁用 java 应用程序 android 中的状态栏,就像用户下拉状态栏时不会 go 向下
你好兄弟使用这个!
使用此代码在您的应用中隐藏状态栏并易于使用
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
如果您想要的是全屏活动,请使用此
public class sample extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setFullScreen();
//add your code
}
private void setFullScreen() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R){
getWindow().getInsetsController().hide(WindowInsets.Type.statusBars() | WindowInsets.Type.statusBars());
getWindow().getInsetsController().setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
}else {
getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN,LayoutParams.FLAG_FULLSCREEN);
}
}
}
如果你说你不打开状态栏,那是不可能的。
android的原生状态栏不能显示和隐藏,系统不允许。 但是您可以创建自己的自定义状态,然后您可以根据需要显示和隐藏它。 这里和示例:custom_status.xml
<com.google.android.material.card.MaterialCardView
android:id="@+id/mToolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:backgroundTint="@color/white"
app:cardCornerRadius="0dp"
app:cardElevation="0dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginHorizontal="15dp"
android:layout_marginVertical="15dp"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:paddingBottom="2dp"
android:textColor="@color/black"
android:textSize="32sp"
app:layout_constraintBottom_toBottomOf="@+id/backButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/backButton"
app:layout_constraintTop_toTopOf="@+id/backButton" />
<ImageView
android:id="@+id/backButton"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="15dp"
android:layout_marginTop="20dp"
android:background="@drawable/ic_circle_solid"
android:backgroundTint="@color/quantum_grey100"
android:padding="7dp"
android:src="@drawable/ic_baseline_arrow_back_24"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
在 java 代码中
public void onScrollStateChanged(AbsListView view, int scrollState) {
final ListView lw = getListView();
if (view.getId() == lw.getId()) {
final int currentFirstVisibleItem = lw.getFirstVisiblePosition();
if (currentFirstVisibleItem > mLastFirstVisibleItem) {
mIsScrollingUp = false;
//mToolbar_container visible
} else if (currentFirstVisibleItem < mLastFirstVisibleItem) {
mIsScrollingUp = true;
//mToolbar_container gone
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.