设置AlertBox标题栏背景颜色标题栏、颜色、背景、AlertBox

由网友(┌;亦旧怡心)分享简介:我如何可以改变背景颜色为alertbox的标题栏?AlertDialog.Builder警报=新AlertDialog.Builder(的getParent());alert.setTitle(样本);alert.show();解决方案 最简单的方法是通过创建扩展对话框,并实现了内搭风格作为参数的构造函数的类的子类...

我如何可以改变背景颜色为alertbox的标题栏?

  AlertDialog.Builder警报=新AlertDialog.Builder(的getParent());
alert.setTitle(样本);
alert.show();
 

解决方案

最简单的方法是通过创建扩展对话框,并实现了内搭风格作为参数的构造函数的类的子类的对话框。然后,让自己的自定义布局了。

在code以显示对话框:

 私人无效的ShowDialog()
{
    CUSTOM_DIALOG对话框=新CUSTOM_DIALOG(这一点,R.style.myCoolDialog);

    dialog.setContentView(R.layout.custom_dialog);
    dialog.setTitle(自定义对话框);

    TextView的文字=(TextView的)dialog.findViewById(R.id.text);
    text.setText(你好,这是一个自定义对话框!);
    ImageView的形象=(ImageView的)dialog.findViewById(R.id.image);
    image.setImageResource(R.drawable.icon);

    dialog.show();
}
 

在code的子类:

 包com.stackoverflow;

进口android.app.Dialog;
进口android.content.Context;

公共类CUSTOM_DIALOG扩展对话框{

    保护CUSTOM_DIALOG(上下文的背景下,诠释主题){
        超(背景下,主题);
        // TODO自动生成构造函数存根
    }

}
 
计算机wold标题文字加背景,office word文档添加背景图片以及背景颜色来美化枯燥乏味的文字...

在风格:myCoolDialog.xml

 <资源>
    <样式名称=myCoolDialog父=机器人:Theme.Dialog>
        <项目名称=机器人:windowBackground> @可绘制/蓝< /项目>
        <项目名称=机器人:colorForeground>#F0F0< /项目>
     < /风格>
< /资源>
 

和最后的布局:custom_dialog.xml

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
              机器人:ID =@ + ID / layout_root
              机器人:方向=横向
              机器人:layout_width =FILL_PARENT
              机器人:layout_height =FILL_PARENT
              机器人:填充=10dp
              >
    < ImageView的机器人:ID =@ + ID /图像
               机器人:layout_width =WRAP_CONTENT
               机器人:layout_height =FILL_PARENT
               机器人:layout_marginRight =10dp
               />
    < TextView的机器人:ID =@ + ID /文
              机器人:layout_width =WRAP_CONTENT
              机器人:layout_height =FILL_PARENT
              机器人:文字颜色=#FFF
              />
< / LinearLayout中>
 

How can I change the background color for an alertbox's title bar?

AlertDialog.Builder alert=new AlertDialog.Builder(getParent());
alert.setTitle("sample");
alert.show();

解决方案

The easiest way is to subclass a dialog by creating a class which extends dialog and implements the constructor which take style as a parameter. Then make your own custom layout to it.

The Code to show the dialog:

private void showDialog()
{
    Custom_Dialog dialog = new Custom_Dialog(this, R.style.myCoolDialog);

    dialog.setContentView(R.layout.custom_dialog);
    dialog.setTitle("Custom Dialog");

    TextView text = (TextView) dialog.findViewById(R.id.text);
    text.setText("Hello, this is a custom dialog!");
    ImageView image = (ImageView) dialog.findViewById(R.id.image);
    image.setImageResource(R.drawable.icon);

    dialog.show();  
}

The code for the subclass:

package com.stackoverflow;

import android.app.Dialog;
import android.content.Context;

public class Custom_Dialog extends Dialog {

    protected Custom_Dialog(Context context, int theme) {
        super(context, theme);
        // TODO Auto-generated constructor stub
    }

}

the style: myCoolDialog.xml

<resources>
    <style name="myCoolDialog" parent="android:Theme.Dialog"> 
        <item name="android:windowBackground">@drawable/blue</item>
        <item name="android:colorForeground">#f0f0</item> 
     </style> 
</resources>

and last the layout:custom_dialog.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/layout_root"
              android:orientation="horizontal"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:padding="10dp"
              >
    <ImageView android:id="@+id/image"
               android:layout_width="wrap_content"
               android:layout_height="fill_parent"
               android:layout_marginRight="10dp"
               />
    <TextView android:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:textColor="#FFF"
              />
</LinearLayout>

阅读全文

相关推荐

最新文章