why my splash screen don't show the images?

前端 未结 3 1432
-上瘾入骨i
-上瘾入骨i 2020-12-06 23:13

I\'ve created one splash screen with android studio 0.1, but when I test it on my phone(nexus s) in debugging mode with usb the image isn\'t show.. why?

this is the

相关标签:
3条回答
  • 2020-12-06 23:54

    Don't use a application context. To know when to use activity context and application context pls check the link below especially the answer by commonsware

    When to call activity context OR application context?

    I tested your code in the post. It works on my device samsung galaxy s3. Only Change i made was having a imageview in the RelativeLayout and set the image for the same in onCreate(). I also used a activity context. Other than that your code is fine.

    Splash screen using handler

    public class Splash extends Activity {
    private static final int SPLASH_TIME = 2 * 1000;// 3 seconds delay
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        ImageView iv= (ImageView) findViewById(R.id.imageView1);
        iv.setBackgroundResource(R.drawable.afor);
        try {
               new Handler().postDelayed(new Runnable() {
    
            public void run() {
    
                Intent intent = new Intent(Splash.this,
                    MainActivity.class);
                startActivity(intent);
    
                Splash.this.finish();
            }     
        }, SPLASH_TIME);
            }
    
        } catch(Exception e){}
    }
     @Override
    public void onBackPressed() {
        this.finish();
        super.onBackPressed();
    }
    }
    

    splash.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" android:background="#ffffaa">
    
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_centerInParent="true"
         />
    
     </RelativeLayout>
    
    0 讨论(0)
  • 2020-12-07 00:12

    Try to change

    Class c extends Activity to Class c extends AppCompatActivity.

    Works to me.

    0 讨论(0)
  • 2020-12-07 00:18

    Try this code

    MainActivity

    public class MainActivity extends Activity {
    
    String EmpID;
    int requestCode;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.splash);          
        Thread timer = new Thread() {
            public void run() {
                try {
                    sleep(2500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } finally {
                    startActivity(new Intent(getApplication(), Main.class));
                     MainActivity.this.finish();
                }
            }
        };
        timer.start();
       }
    }
    

    Splash.xml Remember splash image should be png

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

    0 讨论(0)
提交回复
热议问题