1

我似乎遇到了一个可能很容易解决的烦恼,但我就是不知道如何解决。目标是在打开应用程序时随机输出两个不同的图像(图像:mario.png 和 logo.png)。它工作了很长时间,直到我尝试在清单中将应用程序图标(图片:ic_launcher.png)从默认图标更改为新图标(图片:smoke.png)。当我这样做时,应用程序只会输出 logo.png 和 ic_luancher.png。我尝试将清单更改回 ic_luancher.png 但无济于事。有任何想法吗?

public class MainActivity extends Activity {

private String[] Fact;
private static final Random rgenerator = new Random();
private int[] picArray = {
    R.drawable.logo,  //This actually outputs
    R.drawable.mario, //This one outputs the defualt app icon although it is not the one I want.
};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setBackgroundDrawable(new ColorDrawable(Color.rgb(225, 151, 51)));
    setContentView(R.layout.activity_main);

    Resources res = getResources();
    Fact = res.getStringArray(R.array.Facts);
    String q = Fact[rgenerator.nextInt(Fact.length)];
    TextView tv = (TextView) findViewById(R.id.daily);
    tv.setText(q);

    Drawable d = getResources().getDrawable(picArray[rgenerator.nextInt(picArray.length)]);
    ImageView ptv = (ImageView) findViewById(R.id.imageView1);
    ptv.setImageDrawable(d);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

}

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/background"
android:orientation="vertical" >

<TextView
    android:id="@+id/edit_message"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="50sp"
    android:layout_marginTop="20sp"
    android:text="@string/edit_message"
    android:textColor="#000000"
    android:textSize="30sp" >
</TextView>

<TextView
    android:id="@+id/daily"
    android:layout_width="233dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="50sp"
    android:layout_marginTop="30sp"
    android:maxLines="2"
    android:maxWidth="350sp"
    android:text="@string/daily"
    android:textColor="#000000"
    android:textSize="30sp" />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="50sp"/>

4

0 回答 0