Android的 - 如何编程设置按钮样式中的LinearLayout?

Android的 - 如何编程设置按钮样式中的LinearLayout?

问题描述:

我以编程方式创建的LinearLayout一个AlertDialog有一些按钮。

I am programmatically creating a LinearLayout for an AlertDialog with some buttons.

我WANT 要做到这一点:

<LinearLayout android:id="@+id/footer" android:layout_width="fill_parent"
style="@android:style/ButtonBar">

但随着code是这样的:

But with code like this:

LinearLayout buttons = new LinearLayout(parentContext);
buttons.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams buttonsParams =
    new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
    LayoutParams.WRAP_CONTENT);
topLayout.addView(buttons, buttonsParams);
buttons.setLayoutParams(buttonsParams);
Button btnAdd = new Button(context);
btnAdd.setText("Add");

如何设置按钮的样式(使用一个按钮栏)programmitically?

How can I set the style of the buttons (use a button bar) programmitically?

希望我不是太晚了入党:)

Hope I'm not too late to join the party :)

嗯,样式的可以应用到查看在初始化阶段。例如:

Well, Styles can be applied to a View at initialization phase. For example:

LinearLayout button = new LinearLayout(context, null, android.R.style.ButtonBar);