欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android控件BottomSheet實(shí)現(xiàn)底邊彈出選擇列表

 更新時(shí)間:2020年08月26日 14:52:11   作者:Dream_JK  
這篇文章主要介紹了Android控件BottomSheet實(shí)現(xiàn)底邊彈出選擇列表,比較常用的選擇條件或跳轉(zhuǎn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

底邊彈出一個(gè)選擇列表這是一個(gè)比較常用的選擇條件或跳轉(zhuǎn)的很好的方法,可以很好的隱藏各個(gè)選項(xiàng)。在需要使用時(shí)在底邊彈出。而B(niǎo)ottomSheet就是這樣的一個(gè)控件。

使用

1.導(dǎo)入build

compile 'com.cocosw:bottomsheet:1.3.0'

2.在res/values/colors.xml文件中添加以下代碼:

<!--首頁(yè)item文字顏色-->
<color name="colorSubtitle">#999</color>

<!--列表文字顏色-->
<color name="colorTitle">#666</color>


<color name="colorWhite">#ffffffff</color>

<!--首頁(yè)分割線-->

<color name="colorLine">#EBEBEB</color>

 3.在res/values/styles.xml中添加以下style

<style name="BottomSheet.StyleDialog" parent="BottomSheet.Dialog">
 <item name="android:backgroundDimAmount">0.5</item>
 <item name="android:windowAnimationStyle">@style/BottomSheet.Animation</item>
 <item name="android:textColorPrimary">@color/colorTitle</item>
 <item name="android:textColorSecondary">@color/colorSubtitle</item>
 <item name="android:textSize">15sp</item>
 <item name="android:textColorHint">#42ffffff</item>
 <item name="bs_dialogBackground">@color/colorWhite</item>
 <item name="bs_dividerColor">@color/colorLine</item>
 <item name="bs_numColumns">5</item>
 <item name="bs_listStyle">@style/BottomSheet.List</item>
</style>

 4.在res文件夾中創(chuàng)建一個(gè)menu文件夾,在其下創(chuàng)建列表的布局xml文件,如下創(chuàng)建一個(gè) gank_bottomsheet.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto">
 <item
  android:id="@+id/gank_all"
  android:icon="@drawable/gank_icon_category"
  android:title="列表" />
 <item
  android:id="@+id/gank_ios"
  android:icon="@drawable/gank_icon_collect"
  android:title="收藏" />
 <item
  android:id="@+id/gank_app"
  android:icon="@drawable/gank_icon_ewm"
  android:title="二維碼" />
 <item
  android:id="@+id/gank_qian"
  android:icon="@drawable/gank_icon_girl"
  android:title="女孩" />

</menu>

 5.布局xml中:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:id="@+id/activity_bottom_sheet"
 android:layout_width="match_parent"
 android:orientation="vertical"
 android:layout_height="match_parent"
 >
 <Button
  android:layout_marginTop="80dp"
  android:layout_gravity="center_horizontal"
  android:id="@+id/BS_bt"
  android:background="@android:drawable/dialog_holo_light_frame"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="點(diǎn)擊顯示底部列表" />

</LinearLayout>

6.java文件中的使用:

 public class BottomSheetActivity extends AppCompatActivity {
 private Button button;
 private Context context;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_bottom_sheet);
  getSupportActionBar().hide();
  context=this;
  button=(Button)findViewById(R.id.BS_bt);

  button.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    //當(dāng)點(diǎn)擊Button時(shí),就會(huì)顯示底邊欄,需要new出來(lái)讓后把BottomSheet的style和標(biāo)題title和關(guān)聯(lián)的布局sheet,然后點(diǎn)擊監(jiān)聽(tīng)
    new BottomSheet.Builder(context, R.style.BottomSheet_StyleDialog).title("選擇分類(lèi)").sheet(R.menu.gank_bottomsheet).listener(new DialogInterface.OnClickListener(){
     @Override
     public void onClick(DialogInterface dialog, int which) {

      switch (which){
       case R.id.gank_app:
        Toast.makeText(context,"列表",Toast.LENGTH_SHORT).show();
        break;
       case R.id.gank_all:
        Toast.makeText(context,"收藏",Toast.LENGTH_SHORT).show();
        break;
       case R.id.gank_ios:
        Toast.makeText(context,"二維碼",Toast.LENGTH_SHORT).show();
        break;
       case R.id.gank_qian:
        Toast.makeText(context,"女孩",Toast.LENGTH_SHORT).show();
        break;
      }

     }
    }).show();
    //記得一定要show()出來(lái)

 
   }
  });




 }
}

效果圖:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android實(shí)現(xiàn)將已發(fā)送的短信寫(xiě)入短信數(shù)據(jù)庫(kù)的方法

    Android實(shí)現(xiàn)將已發(fā)送的短信寫(xiě)入短信數(shù)據(jù)庫(kù)的方法

    這篇文章主要介紹了Android實(shí)現(xiàn)將已發(fā)送的短信寫(xiě)入短信數(shù)據(jù)庫(kù)的方法,是Android手機(jī)開(kāi)發(fā)常見(jiàn)的技巧,需要的朋友可以參考下
    2014-09-09
  • Android實(shí)現(xiàn)擴(kuò)大View點(diǎn)擊區(qū)域的三種方式

    Android實(shí)現(xiàn)擴(kuò)大View點(diǎn)擊區(qū)域的三種方式

    在 Android 應(yīng)用開(kāi)發(fā)中,有時(shí)候需要擴(kuò)大 View 的點(diǎn)擊區(qū)域以提高用戶(hù)交互的便利性,尤其是當(dāng)視圖元素較小或用戶(hù)界面密集時(shí),以下提供幾種擴(kuò)大點(diǎn)擊區(qū)域的思路,感興趣的小伙伴跟著小編一起來(lái)看看吧
    2024-08-08
  • Android中利用matrix 控制圖片的旋轉(zhuǎn)、縮放、移動(dòng)

    Android中利用matrix 控制圖片的旋轉(zhuǎn)、縮放、移動(dòng)

    本篇文章是對(duì)Android中利用matrix 控制圖片的旋轉(zhuǎn)、縮放、移動(dòng)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06
  • Android協(xié)程的7個(gè)重要知識(shí)點(diǎn)匯總

    Android協(xié)程的7個(gè)重要知識(shí)點(diǎn)匯總

    在現(xiàn)代Android應(yīng)用開(kāi)發(fā)中,協(xié)程(Coroutine)已經(jīng)成為一種不可或缺的技術(shù),它不僅簡(jiǎn)化了異步編程,還提供了許多強(qiáng)大的工具和功能,可以在高階場(chǎng)景中發(fā)揮出色的表現(xiàn),本文將深入探討Coroutine重要知識(shí)點(diǎn),幫助開(kāi)發(fā)者更好地利用Coroutine來(lái)構(gòu)建高效的Android應(yīng)用
    2023-09-09
  • Android利用POI實(shí)現(xiàn)將圖片插入到Excel

    Android利用POI實(shí)現(xiàn)將圖片插入到Excel

    這篇文章主要為大家詳細(xì)介紹了Android如何利用POI實(shí)現(xiàn)將圖片插入到Excel,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-11-11
  • DialogFragment運(yùn)行原理及使用方法詳解

    DialogFragment運(yùn)行原理及使用方法詳解

    這篇文章主要介紹了DialogFragment運(yùn)行原理及使用方法詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-10-10
  • Android編程中EditText限制文字輸入的方法

    Android編程中EditText限制文字輸入的方法

    這篇文章主要介紹了Android編程中EditText限制文字輸入的方法,涉及Android針對(duì)EditText的監(jiān)聽(tīng)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-11-11
  • Kotlin超簡(jiǎn)單實(shí)現(xiàn)StepView的方法

    Kotlin超簡(jiǎn)單實(shí)現(xiàn)StepView的方法

    這篇文章主要介紹了Kotlin超簡(jiǎn)單實(shí)現(xiàn)StepView的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-11-11
  • Android實(shí)現(xiàn)加載時(shí)提示“正在加載,請(qǐng)稍后”的方法

    Android實(shí)現(xiàn)加載時(shí)提示“正在加載,請(qǐng)稍后”的方法

    在現(xiàn)在的很多應(yīng)用中,當(dāng)在加載的時(shí)候,如果頁(yè)面動(dòng)態(tài)數(shù)據(jù)較多,會(huì)有很長(zhǎng)一段時(shí)間的空白頁(yè)面,如果加上這個(gè)頁(yè)面正在加載的提示,使得應(yīng)用更加人性化。這篇文章就給大家分享了在 Android實(shí)現(xiàn)加載時(shí)提示“正在加載,請(qǐng)稍后”的方法,有需要的朋友們可以參考借鑒。
    2016-10-10
  • Android使用剪切板傳遞數(shù)據(jù)

    Android使用剪切板傳遞數(shù)據(jù)

    這篇文章主要為大家詳細(xì)介紹了Android使用剪切板傳遞數(shù)據(jù),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-03-03

最新評(píng)論