【移動應用開發(fā)技術】Android UI新組件怎么用_第1頁
【移動應用開發(fā)技術】Android UI新組件怎么用_第2頁
【移動應用開發(fā)技術】Android UI新組件怎么用_第3頁
【移動應用開發(fā)技術】Android UI新組件怎么用_第4頁
【移動應用開發(fā)技術】Android UI新組件怎么用_第5頁
已閱讀5頁,還剩7頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

【移動應用開發(fā)技術】AndroidUI新組件怎么用

MaterialDialog/upload/information/20200623/125/123863.pngprivate

void

showDialog1()

{

android.support.v7.app.AlertDialog.Builder

builder

=

new

AlertDialog.Builder(this);

builder.setMessage("讓我們一起飛,我?guī)е?,你帶著錢,來一場說走就走的旅行")

.setNegativeButton("取消",

null)

.setPositiveButton("確定",

null)

.setTitle("Material

Design

Dialog")

.show();

}SwipeRefreshLayout/upload/information/20200623/125/123864.gif<android.support.v4.widget.SwipeRefreshLayout

xmlns:android="/apk/res/android"

xmlns:app="/apk/res-auto"

android:id="@+id/swipe_container"

android:layout_width="match_parent"

android:layout_height="match_parent">

<!--可滑動的組件,比如ScrollView,ListView,GridView,等-->

<ScrollView

android:layout_width="match_parent"

android:layout_height="wrap_content">

<!--添加自己的內容-->

</ScrollView>

</android.support.v4.widget.SwipeRefreshLayout>swipeRefreshLayout

=

findView(R.id.swipe_container);

//設置下拉刷新監(jiān)聽事件

swipeRefreshLayout.setOnRefreshListener(this);

//設置進度條的顏色

swipeRefreshLayout.setColorSchemeColors(Color.RED,

Color.BLUE,

Color.GREEN);

//設置圓形進度條大小

swipeRefreshLayout.setSize(SwipeRefreshLayout.LARGE);

//設置進度條背景顏色

swipeRefreshLayout.setProgressBackgroundColorSchemeColor(Color.DKGRAY);

//設置下拉多少距離之后開始刷新數據

swipeRefreshLayout.setDistanceToTriggerSync(50);LinearLayoutCompat

/upload/information/20200623/125/123865.png<android.support.v7.widget.LinearLayoutCompat

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_gravity="center|center_horizontal"

android:orientation="vertical"

app:divider="@drawable/line"

app:dividerPadding="25dp"

app:showDividers="middle|beginning|end">

<TextView

android:id="@+id/textView"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:gravity="center"

android:paddingTop="10dp"

android:text="CSDN

廢墟的樹"

android:textSize="20sp"

android:textStyle="bold"

/>

<TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:gravity="center"

android:paddingTop="10dp"

android:text="CSDN

廢墟的樹"

android:textSize="20sp"

android:textStyle="bold"

/>

<TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:gravity="center"

android:paddingTop="10dp"

android:text="CSDN

廢墟的樹"

android:textSize="20sp"

android:textStyle="bold"

/>

<TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:gravity="center"

android:paddingTop="10dp"

android:text="CSDN

廢墟的樹"

android:textSize="20sp"

android:textStyle="bold"

/>

<TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:gravity="center"

android:paddingTop="10dp"

android:text="CSDN

廢墟的樹"

android:textSize="20sp"

android:textStyle="bold"

/>

<TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:gravity="center"

android:paddingTop="10dp"

android:text="CSDN

廢墟的樹"

android:textSize="20sp"

android:textStyle="bold"

/>

</android.support.v7.widget.LinearLayoutCompat><?xml

version="1.0"

encoding="utf-8"?>

<shape

xmlns:android="/apk/res/android">

<solid

android:color="@color/material_blue_grey_800"

/>

<!--需要設置高度,否則不顯示-->

<size

android:height="1px"

/>

</shape>ListPopupWindow

/upload/information/20200623/125/123866.pngpublic

void

showListPopup(View

view)

{

String

items[]

=

{"item1",

"item2",

"item3",

"item4",

"item5"};

final

ListPopupWindow

listPopupWindow

=

new

ListPopupWindow(this);

//設置ListView類型的適配器

listPopupWindow.setAdapter(new

ArrayAdapter<String>(SwipeRefreshActivity.this,

android.R.layout.simple_list_item_1,

items));

//給每個item設置監(jiān)聽事件

listPopupWindow.setOnItemClickListener(new

AdapterView.OnItemClickListener()

{

@Override

public

void

onItemClick(AdapterView<?>

parent,

View

view,

int

position,

long

id)

{

Toast.makeText(SwipeRefreshActivity.this,

"the

position

is"

+

position,

Toast.LENGTH_SHORT).show();

//

listPopupWindow.dismiss();

}

});

//設置ListPopupWindow的錨點,也就是彈出框的位置是相對當前參數View的位置來顯示,

listPopupWindow.setAnchorView(view);

//ListPopupWindow

距錨點的距離,也就是相對錨點View的位置

listPopupWindow.setHorizontalOffset(100);

listPopupWindow.setVerticalOffset(100);

//設置對話框的寬高

listPopupWindow.setWidth(300);

listPopupWindow.setHeight(600);

listPopupWindow.setModal(false);

listPopupWindow.show();

}PopupMenu/upload/information/20200623/125/123867.pngpublic

void

showPopupMenu(View

view)

{

//參數View

是設置當前菜單顯示的相對于View組件位置,具體位置系統(tǒng)會處理

PopupMenu

popupMenu

=

new

PopupMenu(this,

view);

//加載menu布局

popupMenu.getMenuInflater().inflate(R.menu.menu_main,

popupMenu.getMenu());

//設置menu中的item點擊事件

popupMenu.setOnMenuItemClickListener(new

PopupMenu.OnMenuItemClickListener()

{

@Override

public

boolean

onMenuItemClick(MenuItem

item)

{

return

false;

}

});

//設置popupWindow消失的點擊事件

popupMenu.setOnDismissListener(new

PopupMenu.OnDismissListener()

{

@

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論