是否可以打开一张图片,该图片存储在res / drawable文件夹中,而Android版本在Image Viewer中?我不懂。我尝试了以下方式
Button ButtonPhase2 = (Button) findViewById(R.id.button1);
ButtonPhase2.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW);
myIntent.setData(Uri.parse("android.resource://de.test.app/" + R.drawable.testbild));
myIntent.setType("image/png");
startActivityForResult(myIntent, 1);
}
});
但我收到错误:
Unable to start Activity ComponentInfo{com.android.gallery/com.android.camera.ViewImage}: java.lang.nullPointerException
我认为这是错误的道路?
答案 0 :(得分:-3)
的xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center" android:orientation="horizontal">
<ImageButton android:id="@+id/anim_btn_play"
android:layout_width="155dp" android:layout_height="80dp"
android:layout_marginLeft="260dp" android:layout_marginTop="150dp"
>
</ImageButton>
</LinearLayout>
Java文件:
ImageButton tns_imgv_back;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.touch_and_show);
{
tns_imgv_back= (ImageButton)findViewById(R.id.anim_btn_play)
tns_imgv_back.setImageResource(R.drawable.icon);
anim_btn_play11.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// you can do any thing over here when you click it will fire
}
});
}}