我似乎遇到了一个可能很容易解决的烦恼,但我无法弄清楚如何。目标是在应用程序打开时随机输出两个不同的图像(图片:mario.png和logo.png)。它工作了很长时间,直到我尝试将默认的app图标(Image:ic_launcher.png)更改为Manifest中的新图标(Image: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"/>