Verzeichnis suchen
android Manifest Manifest.permission Manifest.permission_group android.accessibilityservice AccessibilityService android.accounts Account android.app NotificationManager android.bluetooth BluetoothAdapter BluetoothClass BluetoothClass.Device BluetoothClass.Device.Major BluetoothClass.Service BluetoothDevice BluetoothServerSocket BluetoothSocket android.content SharedPreferences android.database.sqlite SQLiteCursorDriver SQLiteOpenHelper android.graphics Bitmap android.location LocationListener Geocoder GpsStatus GpsStatus.Listener GpsStatus.NmeaListener GpsSatellite android.media AudioFormat AsyncPlayer AudioRecord AudioRecord.OnRecordPositionUpdateListener ThumbnailUtils AudioManager android.net TrafficStats MailTo LocalSocket android.os AsyncTask AsyncTask.Status CountDownTimer Message MessageQueue HandlerThread android.text Html android.util JsonWriter android.view ContextMenu ContextMenu.ContextMenuInfo Display ViewManager View ViewStub ViewTreeObserver ViewParent WindowManager GestureDetector Gravity MenuInflater ScaleGestureDetector SoundEffectConstants android.view.inputmethod InputConnection InputMethod InputMethodSession BaseInputConnection InputMethodManager android.widget AbsListView AbsListView.LayoutParams AbsListView.OnScrollListener AbsListView.RecyclerListener AbsoluteLayout AbsoluteLayout.LayoutParams AbsSeekBar AbsSpinner AdapterView AdapterView.AdapterContextMenuInfo AdapterView.OnItemLongClickListener AdapterView.OnItemSelectedListener AdapterView.OnItemClickListener AnalogClock BaseAdapter BaseExpandableListAdapter Button CheckBox CheckedTextView Checkable Chronometer Chronometer.OnChronometerTickListener CompoundButton CompoundButton.OnCheckedChangeListener CursorAdapter CursorTreeAdapter DatePicker DatePicker.OnDateChangedListener DialerFilter DigitalClock EditText Filter Filter.FilterListener Filter.FilterResults ExpandableListAdapter ExpandableListView.OnChildClickListener ExpandableListView.OnGroupClickListener ExpandableListView.OnGroupCollapseListener ExpandableListView.OnGroupExpandListener Filterable Gallery Gallery.LayoutParams GridView GridLayout GridLayout.Alignment RadioGroup ImageView ImageView.ScaleType HorizontalScrollView ImageButton ImageSwitcher FilterQueryProvider ListAdapter ListView MediaController MultiAutoCompleteTextView MultiAutoCompleteTextView.CommaTokenizer MultiAutoCompleteTextView.Tokenizer QuickContactBadge RadioButton RatingBar RatingBar.OnRatingBarChangeListener RelativeLayout RemoteViews ResourceCursorAdapter ResourceCursorTreeAdapter Scroller ScrollView SearchView SearchView.OnCloseListener SearchView.OnQueryTextListener SearchView.OnSuggestionListener SeekBar SeekBar.OnSeekBarChangeListener SimpleAdapter SimpleAdapter.ViewBinder SimpleCursorAdapter SimpleCursorAdapter.CursorToStringConverter SimpleCursorAdapter.ViewBinder SimpleCursorTreeAdapter SimpleCursorTreeAdapter.ViewBinder SimpleExpandableListAdapter SlidingDrawer SlidingDrawer.OnDrawerCloseListener SlidingDrawer.OnDrawerOpenListener SlidingDrawer.OnDrawerScrollListener Spinner SpinnerAdapter WrapperListAdapter TabHost TabHost.TabSpec TextView TimePicker TimePicker.OnTimeChangedListener Toast TableLayout TableLayout.LayoutParams TableRow TableRow.LayoutParams TabWidget TextSwitcher ToggleButton TwoLineListItem VideoView ViewAnimator ViewFlipper ViewSwitcher ViewSwitcher.ViewFactory ZoomButtonsController ZoomButtonsController.OnZoomListener ZoomButton ZoomControls dalvik.system DexFile
Figuren

ImageButton

农民伯伯

版本:Android 2.2

 

java.lang.Object

android.view.View

android.widget.ImageView

android.widget.ImageButton

 

直接子类:

ZoomButton 

 

类摘要:

显示一个可以被用户点击的图片按钮,默认情况下,ImageButton看起来像一个普通的按钮,在不同状态(如按下)下改变背景颜色。按钮的图片可用通过<ImageButton> XML元素的android:src属性或setImageResource(int)方法指定。

要删除按钮的背景,可以定义自己的背景图片或设置背景为透明。(注:请看

原图和图片按钮,默认图片周围有按钮的背景,选中之后为黄色)

为了表示不同的按钮状态(焦点,选择等),你可以为各种状态定义不同的图片。例如,定义蓝色图片为默认图片,黄色图片为获取时焦点时显示的图片,黄色图片为按钮被按下时显示的图片。一个简单的方法可以做到这点——通过XML"selector."配置,如下:

保存上面的XMLres/drawable/文件夹下(注:注意文件名大小写!),将该文件名作为一个参数设置到ImageButton android:src属性(注:如xml文件名为myselector.xml,那么这里设置为"@drawable/myselector",设置android:background也是可以的,但效果不太一样)。Android根据按钮的状态改变会自动的去XML中查找相应的图片以显示。

<item>元素的顺序很重要,因为是根据这个顺序判断是否适用于当前按钮状态,这也是为什么正常(默认)状态指定的图片放在最后,是因为它只会在pressedfocused都判断失败之后才会被采用。(注:例如按钮被按下时是同时获得焦点的,但是获得焦点并不一定按了按钮,所以这里会按顺序查找,找到合适的就不往下找了。这里按钮被点击了,那么第一个将被选中,且不再在后面查找其他状态。)

参见Form Stuff tutorial

 

 

继承自父类的方法

         public void  setAlpha  (int alpha)

设置ImageButton图片的透明度(注意不是背景图片的)。效果如图:

         参数

                   alpha 透明值0~2550为完全透明,255为完全不透明


Vorheriger Artikel: Nächster Artikel: