如何让我的背景变暗?

时间:2014-01-21 10:43:01

标签: android android-listview background-color android-spinner

我在listview和spinner中成功添加了一些数据。但是当我在模拟器中运行它时,listview和spinner的背景非常轻。为什么我让它们可见?

MainActivity.java

package com.example.task;

//import java.util.ArrayList;
import android.os.Bundle;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Intent;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.format.Time;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.Toast;

public class MainActivity extends Activity implements     OnClickListener,OnItemSelectedListener{

    private int year;
private int month;
private int day;

LoginDataBaseAdapter loginDataBaseAdapter;

String[] fir;

EditText et1,et2,et3,et4;
Button b1,b2,b3;
Spinner spin;
SeekBar bar;

String str,str1,str2,str3,str4;
Integer i,i1,i3;


static final int DATE_DIALOG_ID = 999;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    loginDataBaseAdapter=new LoginDataBaseAdapter(this);
    loginDataBaseAdapter=loginDataBaseAdapter.open();

    et1=(EditText)findViewById(R.id.edit1);
    et2=(EditText)findViewById(R.id.edit2);
    et3=(EditText)findViewById(R.id.edit3);
    et4=(EditText)findViewById(R.id.edit4);

    bar=(SeekBar)findViewById(R.id.seek);
    spin=(Spinner)findViewById(R.id.spin);

    b1=(Button)findViewById(R.id.button1);
    b2=(Button)findViewById(R.id.button2);
    b3=(Button)findViewById(R.id.button3);

    b1.setOnClickListener(this);
    b2.setOnClickListener(this);
    b3.setOnClickListener(this);
    et3.setOnClickListener(this);



    et4.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence arg0, int arg1, int arg2,    int arg3) {
            // TODO Auto-generated method stub

        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                int arg3) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable arg0) {
            // TODO Auto-generated method stub
            bar.setProgress(Integer.parseInt(arg0.toString()));
        }
    });



        fir=getResources().getStringArray(R.array.fir);

     ArrayAdapter<String> adapter=new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_dropdown_item_1line,fir);
     spin.setAdapter(adapter);

     spin.setOnItemSelectedListener(this);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}


@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId())
    {

    case R.id.button1:
        str1=et1.getText().toString();
        str2=et2.getText().toString();
        str3=et3.getText().toString();
        str4=et4.getText().toString();

        loginDataBaseAdapter.insertEntry(str1, str2,str3,str,str4);

        Toast.makeText(getApplicationContext(), "Item added in database", Toast.LENGTH_SHORT).show();
        break;

    case R.id.button2:
        try
        {
        et1.setText("");
        et2.setText("");
        et3.setText("");
        et4.setText("");

        }
        catch(Exception e)
        {

        }
        Toast.makeText(getApplicationContext(), "Clicked Cancel", Toast.LENGTH_SHORT).show();
        break;

    case R.id.button3:
        Intent i2=new Intent(MainActivity.this,ListActivity.class);
        startActivity(i2);
        break;

    case R.id.edit3:
        showDialog(DATE_DIALOG_ID);
        break;

    }
}

@Override
@Deprecated
protected Dialog onCreateDialog(int id) {
    // TODO Auto-generated method stub

    switch(id)
    {
    case DATE_DIALOG_ID:
        return new DatePickerDialog(this, datePickerListener, 
                year, month,day);
    }
    return null;
}

    private DatePickerDialog.OnDateSetListener datePickerListener=new
    DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker view, int selectedYear, int   selectedMonth, int selectedDay) {
            // TODO Auto-generated method stub

            year = selectedYear;
            month = selectedMonth;
            day = selectedDay;

            et3.setText(new   StringBuilder().append(day).append("-").append(month+1).append("-").append(year).append(" "));
        }
    };

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
str=spin.getItemAtPosition(arg2).toString();
Toast.makeText(getApplicationContext(), str, Toast.LENGTH_SHORT).show();
}


@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "No text selected",    Toast.LENGTH_SHORT).show();
}

}

ListActivity.java

package com.example.task;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class ListActivity extends Activity implements OnItemClickListener{

ListView list1;
String s11;

LoginDataBaseAdapter loginDataBaseAdapter;
ArrayList<HashMap<String, String>> datalist;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);

    loginDataBaseAdapter=new LoginDataBaseAdapter(this);
    loginDataBaseAdapter=loginDataBaseAdapter.open();

    list1=(ListView)findViewById(R.id.list);

     datalist=loginDataBaseAdapter.getAllAnimals();
    ArrayAdapter<HashMap<String, String>> adapter=new   ArrayAdapter<HashMap<String,String>>(getApplicationContext(), android.R.layout.simple_dropdown_item_1line,datalist);
    list1.setAdapter(adapter);
    list1.setOnItemClickListener(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.list, menu);
    return true;
}

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    // TODO Auto-generated method stub
    s11=list1.getItemAtPosition(arg2).toString();
    String s12=arg0.getItemAtPosition(arg2).toString();
    Intent inte=new Intent(getApplicationContext(),SingleListItem.class);
    inte.putExtra("s12", s12);
    inte.putExtra("s11", s11);
    startActivity(inte);
//      Intent intw=new Intent(ListActivity.this,SingleListItem.class);
//      startActivity(intw);

}

}

SingleListItem.java

package com.example.task;

import java.util.ArrayList;
import java.util.HashMap;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.widget.TextView;

public class SingleListItem extends Activity {

TextView txtName;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_single_list_item);

    txtName=(TextView)findViewById(R.id.txt_name);


    String s1=getIntent().getExtras().getString("s12");
    txtName.setText(s1);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.single_list_item, menu);
    return true;
}

}

1 个答案:

答案 0 :(得分:0)

在xml中,更改微调器和Listview的背景。

<Listview android:background="@android:color/black"/>

<spinner android:background="@android:color/black"/>