Android的 - 如何编程设置按钮样式中的LinearLayout? [英] Android - How to programmatically set the button style in a Linearlayout?

查看:355
本文介绍了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);

这篇关于Android的 - 如何编程设置按钮样式中的LinearLayout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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