定制RadioButton在前的Spinner
来源:互联网 发布:生命游戏 java代码 编辑:程序博客网 时间:2024/05/17 06:13
效果图:a
代码:
1.。。drawable下定义radio_bg。xml
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:drawable="@drawable/radio_checked"/> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/radio_checked"/> <!-- focused -->
<item android:drawable="@drawable/radio"/> <!-- default -->
</selector>
2===layout下定义spinner_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinner_item_textview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:singleLine="true"
android:textColor="@color/red"
android:textSize="24sp">
</TextView>
3===layout下定义spinner_dropdown_item.xml
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:id = "@+id/spinner_drop_item_view"
android:singleLine="true"
android:textColor="@color/green"
android:textSize="24sp"
style="?android:attr/spinnerDropDownItemStyle"
android:drawableLeft="@drawable/radio_bg"
android:checkMark="@null">
<!-- if the RadioButton put behind text -->
<!-- android:checkMark="@drawable/radio_bg" -->
</CheckedTextView>
4===MainActivity.java
package com.android.tian;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
public class MainActivity extends Activity {
private View testView;
private Spinner mySpinner;
//define an array[] to save "cities"
private static final String[] countriesStr = {"Bejing",
"shanghai","tianjin","DaLian"};
private ArrayAdapter<String> adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mySpinner = (Spinner)findViewById(R.id.spinner_City);
//simple_spinner_item || simplle_spinner_dropdown_item
adapter = new ArrayAdapter<String>(this,R.layout.spinner_item,countriesStr);
//set the item style
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
// adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//add the content in the adapter into the spinner
mySpinner.setAdapter(adapter);
//Selected Event
mySpinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener(){
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int pos, long arg3) {
// TODO Auto-generated method stub
//arg0==spinner,arg1==TextView;This TextView is the one
//included in the Spinner!!!!
testView = arg1;
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
//Touch Screen Event
mySpinner.setOnTouchListener(new Spinner.OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
//Execute animation
//v==spinner
//v.startAnimation(myAnimation);
//v.setVisibility(View.INVISIBLE);
return false;
}
});
//Focus changing
mySpinner.setOnFocusChangeListener(new Spinner.OnFocusChangeListener(){
@Override
public void onFocusChange(View v, boolean hasFocused) {
// TODO Auto-generated method stub
}
});
}
}
- 定制RadioButton在前的Spinner
- [Android]定制RadioButton样式
- Android 定制RadioButton样式
- Android 定制RadioButton样式
- Android 定制RadioButton样式
- Swing定制RadioButton
- Android 定制RadioButton样式
- 组件radiobutton CheckBox Spinner SeekBar
- 下拉列表(Spinner),多选框(CheckBox),单选按钮(RadioButton)的使用
- RadioButton,Switch,AutocompleteTextView,Spinner控件的简单用法(复制可直接运行)
- spinner(下拉列表框),RadioButton(单选按钮),EditText,Adapter的应用
- android常用控件------checkBox RadioButton ImageView Spinner
- RadioGroup、RadioButton以及Spinner学习笔记
- Spinner 和 RadioButton 取值和传值到服务器
- Android-UI组件- RadioButton、CheckBox、 Spinner和ListView
- UI组件详解2---- RadioGroup、RadioButton、CheckBox、ListView、Spinner
- 日本人的名字是姓在前还是名在前
- RadioButton和CheckBox的区别,RadioButton&RadioGroup
- BMPTOPDF
- xt800区别思路
- 谈PHP乱码
- 关于等待多于64个线程的解决方法
- QML之使用C++自定义QML类型(三)
- 定制RadioButton在前的Spinner
- asp.net怎么读取excel
- asp.net怎么读取excel
- asp.net怎么读取excel
- 从BW开发系统传输到BW生产系统的过程
- 51指针定义
- Ajax中status值为500或是12030的问题
- 《当程序员的那些狗日日子》(二十七)大项目
- Keil中如何使用自己生成的LIB库