当我将启动屏幕设为主屏幕时,应用程序无法打开

问题描述 投票:0回答:1

我想做一个双屏应用程序。我想使用按钮从第一个位置通知屏幕切换到主要活动 但应用程序打不开。

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

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
    <uses-feature android:name="android.hardware.sensor.accelerometer" />
    <uses-feature android:name="android.hardware.sensor.compass" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:supportsRtl="true">
        
        <activity
        
        android:name=".SplashActivity"
            
            android:label="@string/app_name"
            android:exported="true"
            android:screenOrientation="portrait">
           <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />

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

</manifest>


(第一屏不是闪屏,只是名字是这样的)

SplashActivity.java在这里:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.activity_splash);
        
        tikla1 =(Button) findViewById(R.id.tikla);
        kapat1 =(Button) findViewById(R.id.kapat);
        text1 =(TextView) findViewById(R.id.baslik);
        text2 =(TextView) findViewById(R.id.text1);
        text3 =(TextView) findViewById(R.id.text2);
        image1 =(ImageView) findViewById(R.id.konumresmi);
        checkLocationPermission();

        tikla1.setOnClickListener(new View.OnClickListener() {

                public void onClick(View d) {
                    
                    
                    Intent myIntent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    startActivity(myIntent);
                    Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                    startActivity(intent);
                }
            });
        

        kapat1.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                    startActivity(intent);
                }
            });
    }

activity_splash.xml 文件在这里:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/konumi">

    <TextView
        android:id="@+id/baslik"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Konumunuzu kullanın"
        android:textSize="60sp"
        android:layout_gravity="center_horizontal"
        android:textStyle="bold"
        android:layout_marginTop="50dp"/>

    <TextView
        android:id="@+id/text1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Değişen konumunuza göre otomatik olarak güncellenen namaz vakitleri için Ezan Vakti'nin konumunuzu her zaman kullanmasına izin verin."
        android:textSize="20sp"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="50dp"/>

    <TextView
        android:id="@+id/text2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Ezan Vakti namaz vakitlerini ve kıble yönünü  göstermek için arka plandaki konumu kullanacak."
        android:textSize="20sp"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="70dp"/>

    <ImageView
        android:id="@+id/konumresmi"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/konumi"
        android:layout_gravity="center"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        android:layout_centerInParent="true"/>

    <Button
        android:id="@+id/tikla"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="200dp"
        android:layout_marginBottom="45dp"
        android:text="Konumu aç"
        android:background="#0009ff"
        android:textColor="#ffffff"
        android:textSize="15sp"
        android:textStyle="bold"/>

    <Button
        android:id="@+id/kapat"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="50dp"
        android:layout_marginBottom="45dp"
        android:text="Hayir,tesekkurler"
        android:background="#ffffff"
        android:textColor="#0009ff"
        android:textSize="15sp"
        android:textStyle="bold"/>

</RelativeLayout>

我尝试使用第一个屏幕上的按钮切换到第二个屏幕,但应用程序无法打开。

如果您能帮助我,我会很高兴。

java android android-intent screen splash-screen
1个回答
0
投票

您的问题在

activity_splash.xml
。您的
layout_width
layout_height
TextView
ImageView
属性设置为
match_parent
。这意味着这些组件与您的
Button
重叠并使它们无法单击。

调整布局并避免将

match_parent
用于
TextView
ImageView
。您应该将其
layout_width
layout_height
更改为
wrap_content
并结合调整其他属性以获得预期的布局。

例如:

<TextView
    android:id="@+id/baslik"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Konumunuzu kullanın"
    android:textSize="60sp"
    android:layout_gravity="center_horizontal"
    android:textStyle="bold"
    android:layout_marginTop="50dp"/>

<TextView
    android:id="@+id/text1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Değişen konumunuza göre otomatik olarak güncellenen namaz vakitleri için Ezan Vakti'nin konumunuzu her zaman kullanmasına izin verin."
    android:textSize="20sp"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="50dp"/>

<TextView
    android:id="@+id/text2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Ezan Vakti namaz vakitlerini ve kıble yönünü  göstermek için arka plandaki konumu kullanacak."
    android:textSize="20sp"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="70dp"/>

<ImageView
    android:id="@+id/konumresmi"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/konumi"
    android:layout_gravity="center"
    android:adjustViewBounds="true"
    android:scaleType="centerCrop"
    android:layout_centerInParent="true"/>
© www.soinside.com 2019 - 2024. All rights reserved.