一些基础的控件

2 篇文章 0 订阅
1、Switch
<Switch
        android:id="@+id/switch1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button1"
        android:layout_below="@+id/button1"
        android:layout_marginTop="58dp"
        android:text="wifi" />

1.1、获取到该控件

Switch btnSwitch=(Switch) findViewById(R.id.switch1);

2、RadioButton

<RadioButton
            android:id="@+id/radio0"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:checked="true"
            android:button="@null"
            android:textColor="#ffffffff"
            android:drawableTop="@drawable/ic_launcher"
            android:text="推荐" 
            android:gravity="center_horizontal"/>
3、ScrollView(内部可以装一个组件,就会具有滑动的效果了)

<ScrollView 
        android:layout_width="match_parent"
        android:layout_height="match_parent">
</ScrollView>
4、搜索框SearchView

<SearchView
        android:id="@+id/searchView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true" >
    </SearchView>
4.1、用特殊的方法来设置SearchView的blackGround

private void setSearchView() {
		SearchView sv = (SearchView) findViewById(R.id.searchView1);
		sv.onActionViewExpanded();// 默认展开
		// 获得字符串指定的资源id
		int id = sv.getResources().getIdentifier("android:id/search_plate",
				null, getPackageName());
		// 根据id找到对应的布局
		LinearLayout layout = (LinearLayout) sv.findViewById(id);
		// 设置layout的背景
		layout.setBackgroundResource(R.drawable.editor_background_01);
		// 添加监听器
		sv.setOnQueryTextListener(this);
	}
4.2、位searchView设置OnQueryTextListener监听器

/** 输入完成点击软键盘的搜索按钮时执行此方法 */
	@Override
	public boolean onQueryTextSubmit(String query) {
		Log.i("TAG", "onQueryTextSubmit.query=" + query);
		return false;
	}

	/** 输入框内容发生变化会执行此方法 */
	@Override
	public boolean onQueryTextChange(String newText) {
		Log.i("TAG", "onQueryTextChange.newText=" + newText);
		adapter.getFilter().filter(newText);
		return true;
	}
5、各种进度条(Bar)

<ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="32dp"
        android:layout_marginTop="24dp" />

    <ProgressBar
        android:id="@+id/progressBar2"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/progressBar1"
        android:layout_marginTop="15dp" />

    <!-- 拖动条 -->
    <SeekBar
        android:id="@+id/seekBar1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/progressBar2"
        android:layout_marginTop="46dp" />

    <!-- ratingbar -->
    <RatingBar
        android:id="@+id/ratingBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/seekBar1"
        android:layout_below="@+id/seekBar1"
        android:layout_marginTop="44dp" />









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值