最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android使用setCustomTitle()方法自定義對話框標(biāo)題

 更新時間:2016年02月12日 20:08:43   作者:MSTK  
Android有自帶的對話框標(biāo)題,但是不太美觀,如果要給彈出的對話框設(shè)置一個自定義的標(biāo)題,使用AlertDialog.Builder的setCustomTitle()方法非常方便,接下來通過本文給大家介紹Android使用setCustomTitle()方法自定義對話框標(biāo)題,感興趣的朋友一起學(xué)習(xí)吧

Android有自帶的對話框標(biāo)題,但是不太美觀,如果要給彈出的對話框設(shè)置一個自定義的標(biāo)題,使用AlertDialog.Builder的setCustomTitle()方法。

運行效果如下,左邊是點擊第一個按鈕,彈出Android系統(tǒng)自帶的對話框(直接用setTitle()設(shè)置標(biāo)題);右邊是點擊第二個按鈕,首先inflate一個View,然后用setCustomTitle()方法把該View設(shè)置成對話框的標(biāo)題。

定義一個對話框標(biāo)題的title.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="wrap_content"
android:background="@color/white"
android:gravity="center_vertical"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/patient_top"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:background="@color/green"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical" >
<TextView
android:id="@+id/txtPatient"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="選擇城市"
android:textColor="@color/white"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>

MainActivity的布局文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.hzhi.dialogtest.MainActivity" >
<Button
android:id="@+id/btn01"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="選擇城市1" />
<Button
android:id="@+id/btn02"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="選擇城市2" />
</LinearLayout>

MainActivity.java文件:

package com.hzhi.dialogtest;
import android.support.v7.app.ActionBarActivity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends ActionBarActivity implements OnClickListener{ 
final String[] cities = new String[6];
Button button_01, button_02;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView(){ 
cities[0] = "北京";
cities[1] = "上海";
cities[2] = "深圳";
cities[3] = "廣州";
cities[4] = "杭州";
cities[5] = "成都"; 
button_01 = (Button) findViewById(R.id.btn01);
button_01.setOnClickListener(this); 
button_02 = (Button) findViewById(R.id.btn02);
button_02.setOnClickListener(this); 
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.btn01:
AlertDialog.Builder builder1 = new AlertDialog.Builder(MainActivity.this);
builder1.setItems(cities, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{

}
}); 
builder1.setTitle("選擇城市");
builder1.show();
break;
case R.id.btn02:
LayoutInflater layoutInflater = LayoutInflater.from(MainActivity.this);
View mTitleView = layoutInflater.inflate(R.layout.title, null);
AlertDialog.Builder builder2 = new AlertDialog.Builder(MainActivity.this);
builder2.setItems(cities, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{

}
});
builder2.setCustomTitle(mTitleView);
builder2.show();
break;
}
} 
}

以上所述是小編給大家分享的Android使用setCustomTitle()方法自定義對話框標(biāo)題,希望對大家有所幫助。

相關(guān)文章

  • RecyclerView自定義分割線

    RecyclerView自定義分割線

    這篇文章主要為大家詳細(xì)介紹了RecyclerView自定義分割線的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-09-09
  • Android調(diào)用外置攝像頭的方法

    Android調(diào)用外置攝像頭的方法

    這篇文章主要為大家詳細(xì)介紹了Android調(diào)用外置攝像頭的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • 在Flutter中正確處理文本縮放的解決方案

    在Flutter中正確處理文本縮放的解決方案

    這篇文章主要介紹了在Flutter中正確處理文本縮放的解決方案,本教程的結(jié)構(gòu)首先介紹最簡單且最有影響力的解決方案,后面的部分涵蓋了較難實施且總體影響較小的解決方案,但它們對于解決特定情況很有用,需要的朋友可以參考下
    2024-06-06
  • Android?TextView跑馬燈實現(xiàn)原理及方法實例

    Android?TextView跑馬燈實現(xiàn)原理及方法實例

    字的跑馬燈效果在移動端開發(fā)中是一個比較常見的需求場景,下面這篇文章主要給大家介紹了關(guān)于Android?TextView跑馬燈實現(xiàn)原理及方法的相關(guān)資料,需要的朋友可以參考下
    2022-05-05
  • 詳解Android單元測試方法與步驟

    詳解Android單元測試方法與步驟

    這篇文章給大家分享了Android單元測試方法與步驟的相關(guān)知識點,有興趣和需要的朋友參考學(xué)習(xí)下。
    2018-07-07
  • Android 讀取sdcard上的圖片實例(必看)

    Android 讀取sdcard上的圖片實例(必看)

    下面小編就為大家?guī)硪黄狝ndroid 讀取sdcard上的圖片實例(必看)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-03-03
  • Android neon 優(yōu)化實踐示例

    Android neon 優(yōu)化實踐示例

    這篇文章主要為大家介紹了Android neon 優(yōu)化實踐示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09
  • android 獲取APP的唯一標(biāo)識applicationId的實例

    android 獲取APP的唯一標(biāo)識applicationId的實例

    下面小編就為大家分享一篇android 獲取APP的唯一標(biāo)識applicationId的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-02-02
  • RecyclerView的簡單使用

    RecyclerView的簡單使用

    這篇文章主要為大家詳細(xì)介紹了RecyclerView的簡單使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • 安卓(Android)開發(fā)之分享帶文字的圖片

    安卓(Android)開發(fā)之分享帶文字的圖片

    用過微信分享SDK的都應(yīng)該知道,微信分享到朋友圈的時候是不能同時分享圖片和文字的,只要有縮略圖,那么文字就不會生效。那么問題就來了,如果我們想把APP內(nèi)的某些內(nèi)容連帶圖片一起分享到微信,是不是沒辦法了呢?下面一起來看看怎么解決。
    2016-08-08

最新評論

台山市| 墨竹工卡县| 伊吾县| 徐州市| 泌阳县| 崇仁县| 老河口市| 屏南县| 贵南县| 石门县| 通道| 兰溪市| 田东县| 东至县| 武胜县| 广南县| 正镶白旗| 崇信县| 益阳市| 洛南县| 蒲城县| 乐都县| 从江县| 盐源县| 马关县| 兴安县| 青神县| 璧山县| 修武县| 北安市| 吉木乃县| 喀喇沁旗| 岫岩| 白水县| 新民市| 措美县| 东丰县| 濮阳县| 龙陵县| 巴林右旗| 许昌市|