从初始屏幕删除标题栏

时间:2018-07-28 18:19:19

标签: android android-studio

如何从启动屏幕中删除标题栏?

我有两个活动(“主要活动”和“初始屏幕活动性”)。我为两个活动使用了代码package com.example.acer; import android.app.Activity; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Window; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; public class MainActivity extends Activity { public WebView webView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); //remove App Title bar setContentView(R.layout.activity_main); webView=(WebView)findViewById(R.id.webView); WebSettings webSettings=webView.getSettings(); webSettings.setJavaScriptEnabled(true); webView.loadUrl("http://alkhaleej-med.com/"); webView.setWebViewClient(new WebViewClient()); } @Override public void onBackPressed(){ if(webView.canGoBack()){ webView.goBack(); }else{ super.onBackPressed(); } } } ,以隐藏标题栏。因此,它已从主要活动中删除,但未从初始屏幕活动中删除。

初始屏幕截图: https://drive.google.com/file/d/17dC-REuko1zoQztUlUVcZQBkO4mEjhsK/view?usp=sharing

主要活动的屏幕截图: https://drive.google.com/file/d/14GmY72IRl8_--PGfo2qr7abrcZj4zxbj/view?usp=sharing

代码如下:

MainActivity.Jave:

package com.example.acer;


import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;

public class SplashScreen extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE); //remove App Title bar
        setContentView(R.layout.activity_splash_screen);

        Thread myThread = new Thread(){
            @Override
            public void run() {
                try {
                    sleep(4000);
                    Intent intent = new Intent(getApplicationContext(),MainActivity.class);
                    startActivity(intent);
                    finish();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        myThread.start();
    }
}

SplashScreen.jave:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    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">



    <WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp" />


</RelativeLayout>

Activity_Main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".SplashScreen">



    <ImageView
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:src="@drawable/splash_logo"
        android:layout_centerInParent="true"/>

</RelativeLayout>

Activity_splash_screen.xml:

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

    <uses-permission android:name="android.permission.INTERNET" />

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

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

</manifest>

AndroidManifest.xml:

<ContentPage.Content>
    <StackLayout>
        <ListView x:Name="ItemsListView" ItemsSource="{Binding Items}" VerticalOptions="FillAndExpand" HasUnevenRows="true" RefreshCommand="{Binding LoadItemsCommand}" IsPullToRefreshEnabled="true" IsRefreshing="{Binding IsBusy, Mode=OneWay}" CachingStrategy="RecycleElement" ItemSelected="OnItemSelected">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Orientation="Horizontal">
                            <StackLayout Padding="10">
                                <Label Text="{Binding Summary}" LineBreakMode="NoWrap" Style="{DynamicResource ListItemTextStyle}" FontSize="Medium" />
                                <Label Text="{Binding Reporter}" LineBreakMode="NoWrap" Style="{DynamicResource ListItemDetailTextStyle}" FontSize="Micro"  />
                            </StackLayout>
                            <StackLayout Orientation="Horizontal" HorizontalOptions="EndAndExpand">
                                <Label Text="{Binding Start}" FontSize="Medium" VerticalOptions="Center"/>
                                <Switch IsToggled="{Binding Result}" Toggled="Handle_Toggled"  VerticalOptions="Center"/>
                            </StackLayout>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</ContentPage.Content>

谢谢。

2 个答案:

答案 0 :(得分:0)

转到res-values-styles,然后将基本主题更改为NoActionBar 例如

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

答案 1 :(得分:0)

您已经到了一半:

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);