定制的Andr​​oid DialogFragment [英] Customizing android DialogFragment

查看:167
本文介绍了定制的Andr​​oid DialogFragment的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在的IAM IAM Android.Now初学者级程序员的小应用程序开发后,和我有一个dial​​ogFragment.Everything完美工作,其显示的对话框also.But我有配色方案一些困难。我已经改变了布局和背景颜色,但它的标题栏颜色保持同样的白色,也标题文本颜色为蓝色,并在一个蓝线(需要将其变为绿色)。怎么我能做到这一点?
请大家帮我

iam a beginner level programmer in Android.Now iam after a small app development and i have a dialogFragment.Everything is perfectly working and its displaying Dialog box also.But i have some difficulties with color scheme. I have changed the background color of layout and but its title bar color remains same white and also title text color blue and a blue line under that(need to change it to green).How i can achieve this? please help me

这是我的片段code

here is my fragment code

public class ClientInfofrag extends DialogFragment {

public ClientInfofrag()
{

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
     View view = inflater.inflate(R.layout.clientinfolayout, container);
     getDialog().setTitle("Client Info");

     return view;
}
}

感谢您

推荐答案

由于您使用的是 .setTitle()方法,它只是设置与defualt设置标题如白色背景。如果您想自定义标题背景颜色,你需要有一个XML做到这一点。此外,对于DialogFragments,从我的知识和经验,你应该使用公共对话框onCreateDialog 而不是公开查看onCreateView 。这样,你返回一个对话框,而不是只是一个视图,然后您可以只需调用 .show()上,它会显示您的对话框。下面是一个例子:

Since you are using the .setTitle() method it is only setting the title with the defualt settings, such as the white background. If you want to customize the title background color you will need to have an xml to do that. Also, for DialogFragments, from my knowledge and experience, you should use public Dialog onCreateDialog instead of public View onCreateView. That way you return a Dialog as opposed to just a View that you can then just call .show() on and it will display your dialog. Here is an example:

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();

    Bundle args = getArguments();
    currentName = args.getString(ARG_CURRENT_NAME);

    builder.setView(inflater.inflate(R.layout.name_dialog, null));
    builder.setTitle("Rename Rapper Program");
    builder.setMessage("Enter a new name for " + currentName + ":"); 
    builder.setPositiveButton("Rename", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            newName = (EditText) getDialog().findViewById(R.id.new_name);
            newProgName = newName.getText().toString();
            mRename.renameProgram(currentName, newProgName);
        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dismiss();
        }
    });

    return builder.create();
}

下面是一个例子对话XML,虽然它不是在上述DialogFragment被夸大了的xml:

Here is an example dialog xml, though it is not the xml that is being inflated in the above DialogFragment:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <TextView android:drawableLeft="@drawable/login"
        android:layout_width="match_parent"
        android:layout_height="64dp"
        android:background="#FCD116"
        android:text="@string/login"
        android:textSize="36sp"/>
    <EditText android:id="@+id/username"
        android:inputType="textEmailAddress"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:layout_marginLeft="4dp"
        android:layout_marginRight="4dp"
        android:layout_marginBottom="4dp"
        android:hint="@string/un"/>
    <EditText android:id="@+id/password"
        android:inputType="textPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="4dp"
        android:layout_marginLeft="4dp"
        android:layout_marginRight="4dp"
        android:layout_marginBottom="16dp"
        android:fontFamily="sans-serif"
        android:hint="@string/pw"/>

</LinearLayout>

的LinearLayout 正在建立的子项的其余部分进行相应的设置。第一个的TextView 充当我的头衔栏,然后在的EditText 是在对话框的身体。我对XML没有按钮,因为我设置内编程的 onCreateDialog 那些如上面code的另一片段。

The LinearLayout is setting up the rest of the child items to be placed accordingly. The first TextView acts as my "title" bar and then the EditTexts are the "body" of the dialog. I have no buttons in the xml because I set those programmatically within the onCreateDialog like in the other snippet of code above.

这篇关于定制的Andr​​oid DialogFragment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆