1

我的申请有问题。基本上它的作用是,当我单击一个按钮时,它会在滚动视图上创建 3 个字段(2 个 editText 和 1 个微调器)。事情很好,我唯一遇到的问题与样式有关,活动 bgColor 是白色的(与应用程序的其余部分一样)但是,当我以编程方式创建元素时,这些元素没有我的其余部分的外观应用程序。editTexts 是白色的,带有白色字母(由于我的 bgColor 也是白色的,因此无法阅读),并且与微调器相同。我能做些什么?这是一段代码,因此您可以在这里看到我在做什么。

public class AddIngredients extends Activity {
public int Count = 0;
public String[] spinnerArray = {"Gr", "kg", "Cups", "ml", "L", "oz"};
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.addingredients);
    final TableLayout lm = (TableLayout) findViewById(R.id.TableMain);

    TableLayout.LayoutParams params = new TableLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    Button addMore = (Button)findViewById(R.id.addmore);
    addMore.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            TableRow ll = new TableRow(getApplicationContext());
            //ll.setOrientation(LinearLayout.HORIZONTAL);


            EditText product = new EditText(getApplicationContext());
            product.setHint(" Ingredient "+Count +"    ");

            // Create Button
            EditText amount = new EditText(getApplicationContext());
                // Give button an ID
                amount.setId(Count);
                amount.setHint("Quantity");

            final Button btn2 = new Button(getApplicationContext());

                btn2.setId(Count);
                btn2.setText("Remove " + Count);

            Spinner spinner = new Spinner(getApplicationContext());
            ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_dropdown_item, spinnerArray);
            spinner.setAdapter(spinnerArrayAdapter);

            ll.addView(product);
            ll.addView(amount);
            ll.addView(spinner);
            lm.addView(ll);
            Count = Count + 1;

我知道我的 XML 运行良好,因为如果我在我的 xml 上创建 3 个视图,它们看起来很棒。PD:提前感谢您的帮助!问候。

4

3 回答 3

1

以下是我如何设置编辑文本行和其他与主题相关的 android 视图的颜色。

http://android-holo-colors.com/

我只是选择了我想要的颜色和视图,然后将它们解压缩到我的 res 文件夹中,然后根据 android 教程设置主题。

我建议先备份你的 res 文件夹,以防你不喜欢结果。

阁楼

于 2014-05-13T16:27:10.343 回答
1

您可以使用

amount.setTextColor(Color.BLACK);

将文本的颜色设置为黑色或任何其他
相同的颜色可用于微调器

于 2014-05-13T16:06:46.140 回答
0

我的代码有错误。创建字段时,我使用的是 (getApplicationContext());. 我使用MyApplicationName.this.

于 2014-05-15T11:46:31.627 回答