Android RatingBar星星評分控件實例代碼
更新時間:2017年06月07日 09:45:34 作者:DistanceZK
本文通過實例代碼給大家介紹了Android RatingBar星星評分控件,非常不錯,具有參考借鑒價值,需要的朋友參考下吧
效果圖:
直接上代碼:
xml文件:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.blogtest.MainActivity"> <!--numStars設(shè)置星星的數(shù)量,stepSize默認(rèn)的評分--> <RatingBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/rb_main_rating" android:numStars="5" android:stepSize="0.5" /> </LinearLayout>
Java代碼:
package com.example.blogtest; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Gravity; import android.widget.RatingBar; import android.widget.Toast; public class MainActivity extends AppCompatActivity { private RatingBar rb_main_rating; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //獲得RatingBar的控件 rb_main_rating = (RatingBar) findViewById(R.id.rb_main_rating); //給控件設(shè)置監(jiān)聽事件 rb_main_rating.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() { @Override public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { Toast t=Toast.makeText(MainActivity.this,"您的評分為:"+rating,Toast.LENGTH_SHORT); t.setGravity(Gravity.CENTER,0,0); t.show(); } }); } }
以上所述是小編給大家介紹的Android RatingBar 評分控件,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
Android 對手機網(wǎng)絡(luò)的檢測和監(jiān)聽的方法示例
本篇文章主要介紹了Android 對手機網(wǎng)絡(luò)的檢測和監(jiān)聽的方法示例,主要使用BroadcastReceiver廣播接收器來接收網(wǎng)絡(luò)狀態(tài),現(xiàn)在分享給大家,也給大家做個參考,有興趣的一起來了解一下2018-03-03Android Toolbar自定義標(biāo)題標(biāo)題居中的實例代碼
這篇文章主要介紹了Android Toolbar自定義標(biāo)題 標(biāo)題居中的實例代碼,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2018-08-08淺析Kotlin使用infix函數(shù)構(gòu)建可讀語法流程講解
這篇文章主要介紹了淺析Kotlin使用infix函數(shù)構(gòu)建可讀語法,我們在Kotlin中就多次使用A to B這樣的語法結(jié)構(gòu)構(gòu)建鍵值對,包括Kotlin自帶的mapOf()函數(shù),這種語法結(jié)構(gòu)的優(yōu)點是可讀性強2023-01-01Android編程之文件讀寫操作與技巧總結(jié)【經(jīng)典收藏】
這篇文章主要介紹了Android編程之文件讀寫操作與技巧,結(jié)合實例形式總結(jié)分析了Android常見的文件與目錄的讀寫操作,及相關(guān)函數(shù)的使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下2016-06-06Android實現(xiàn)可使用自定義透明Dialog樣式的Activity完整實例
這篇文章主要介紹了Android實現(xiàn)可使用自定義透明Dialog樣式的Activity,結(jié)合完整實例形式分析了Android Activity自定義style的操作步驟與相關(guān)技巧,需要的朋友可以參考下2016-07-07