【问题标题】:Getting troubles making status bar hovering the activity使状态栏悬停在活动上时遇到问题
【发布时间】:2019-11-22 09:02:08
【问题描述】:

我有一个网站,我决定为它制作一个Android应用程序,但我实际上是在c++上的win32下编写的,从来没有在Android下编程过。所以我决定只制作一个 Blink 渲染实例,使其适合我的应用程序的屏幕尺寸并自动加载我的网站。另外我希望状态栏悬停在“活动”上,搜索互联网但不能这样做,所以请指出我错在哪里。东西应该适用于 Android 4.4 及更高版本。在 Android Studio 中工作

我现在有什么:

我想做什么:

我的代码:

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:fitsSystemWindows="true">


<WebView
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    />

styles.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">#000000</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowTranslucentStatus">true</item>
</style>

MainActivity.java

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE|View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

    WebView myWebView = findViewById(R.id.webview);
    myWebView.setWebViewClient(new WebViewClient());
    myWebView.loadUrl("http://somesite.com");
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);


}
}

【问题讨论】:

    标签: android web-applications statusbar


    【解决方案1】:

    在 onCreate 上试试这个,这将使两者都透明

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    

    或者试试

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    

    【讨论】:

    • 两个是谁?看来我已经有了一个透明的状态栏,但是我需要把它下面的活动转移一下
    • 你试过了吗?我已经编辑并尝试第二个也
    • 对不起,我有一个旧硬件,我无法运行 Android 模拟器。现在我在图书馆尝试下载任何便携式模拟器进行测试
    • 不,没有任何改变。我把 getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);在 getWindow().getDecorView(... 之后
    【解决方案2】:

    在您的 webview 顶部添加进度条

    <ProgressBar android:id="@+id/pB1"
        style="?android:attr/progressBarStyleHorizontal" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_centerVertical="true"
        android:padding="2dip">
    </ProgressBar>
    

    然后你需要像这样在进度条上设置进度状态:

    myWebView.setWebChromeClient(new WebChromeClient() {
                public void onProgressChanged(WebView view, int progress) {
                   if(progress < 100 && pbar.getVisibility() == ProgressBar.GONE){
                       pbar.setVisibility(ProgressBar.VISIBLE);
                       }
    
                   pbar.setProgress(progress);
                   if(progress == 100) {
                       pbar.setVisibility(ProgressBar.GONE);
                      }
                }
            });
    

    【讨论】:

    • 进展?你的意思是状态栏(有时间、电池和其他东西的东西)?还是一样?
    • pbar 也未定义
    猜你喜欢
    • 2019-02-17
    • 1970-01-01
    • 2018-03-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-19
    • 2016-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多