日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android实现连续并排的若干个TextView单击改变背景颜色达到选项卡Tab栏切换效果...

發(fā)布時(shí)間:2024/1/17 Android 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android实现连续并排的若干个TextView单击改变背景颜色达到选项卡Tab栏切换效果... 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

《Android實(shí)現(xiàn)連續(xù)并排的若干個(gè)TextView單擊改變背景顏色達(dá)到選項(xiàng)卡Tab欄切換效果》

實(shí)現(xiàn)的組件交互目的很簡(jiǎn)單,就是要達(dá)到類似tab選項(xiàng)卡的導(dǎo)航欄一樣,當(dāng)用戶點(diǎn)擊了連續(xù)并排的若干個(gè)TextView其中之一時(shí)候,要產(chǎn)生一定的交互效果(背景顏色改變等)。這種實(shí)現(xiàn)的方式有不少可選方案,現(xiàn)在通過背景的selector.xml實(shí)現(xiàn)。

效果如下:

A。初始狀態(tài):


B。當(dāng)用戶單擊了TextView 2,但此時(shí)用戶的手指一直在按下并未松開的狀態(tài),(注意交互設(shè)計(jì)效果!TextView 2的背景顏色變成黃色):


C。用戶的手指在TextView 2上松開、離開設(shè)備屏幕后的狀態(tài):


現(xiàn)在給出全部實(shí)現(xiàn)代碼。

一個(gè)非常簡(jiǎn)單的用于測(cè)試的main activity:

package zhangphil.change;import android.app.Activity; import android.os.Bundle;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);} }

重點(diǎn)是activity_main.xml中關(guān)于TextView的屬性配置和selector.xml。

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="horizontal" ><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_gravity="center_vertical"android:layout_weight="1"android:background="@drawable/selector"android:clickable="true"android:focusable="true"android:focusableInTouchMode="true"android:text="1" /><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_gravity="center_vertical"android:layout_weight="1"android:background="@drawable/selector"android:clickable="true"android:focusable="true"android:focusableInTouchMode="true"android:text="2" /><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_gravity="center_vertical"android:layout_weight="1"android:background="@drawable/selector"android:clickable="true"android:focusable="true"android:focusableInTouchMode="true"android:text="3" /><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_gravity="center_vertical"android:layout_weight="1"android:background="@drawable/selector"android:clickable="true"android:focusable="true"android:focusableInTouchMode="true"android:text="4" /></LinearLayout>

每一個(gè)TextView用到的用于設(shè)置background的selector.xml。

selector.xml:

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:drawable="@drawable/red" android:state_focused="true"/><item android:drawable="@drawable/orange" android:state_pressed="true"/><item android:drawable="@drawable/green"/></selector>


其余的就是一些基礎(chǔ)的資源文件,圖片:

green.png


red.png


orange.png



總結(jié)

以上是生活随笔為你收集整理的Android实现连续并排的若干个TextView单击改变背景颜色达到选项卡Tab栏切换效果...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。