我是android
的新手,现在我陷入了困境。
我希望在菜单项Circle上的用户imageview
更改click
的形状。
drawable
文件夹中的 circle_shape.xml 文件。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomRightRadius="10dp"/>
<solid android:color="#FF44FF"/>
</shape>
我的java文件 Shape.java
package com.example.mixapp;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;
public class Shape_with_Spinner extends Activity {
Spinner shapeSpinner;
ImageView imgMaster;
private Drawable drawable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shape_with__spinner);
try {
imgMaster = (ImageView) findViewById(R.id.imgMaster);
Toast.makeText(this, "in try part ", Toast.LENGTH_LONG).show();
} catch (Exception e) {
Log.i("Magaj jay che have", ""+e.getLocalizedMessage());
Toast.makeText(this, "in catch part : "+e.getMessage(), Toast.LENGTH_LONG).show();
}
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch (item.getItemId()) {
case R.id.rect:
drawable = getDrawable(R.drawable.circle_shape);
break;
default:
break;
}
return super.onMenuItemSelected(featureId, item);
}
}
布局文件夹中的和 Shape.xml 文件。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.mixapp.Shape_with_Spinner" >
<Spinner
android:id="@+id/shapeSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:entries="@array/Spinner_value"/>
<ImageView
android:id="@+id/imgToShape"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
任何帮助都会很明显。 :)