我在Top上有一个RelativeLayout,包括EditTexts和一个FrameLayout(就像列表的框架一样),它包含一个ListView。当我在EditText中单击Background时,只要键盘处于活动状态且EditTexts为空,FrameLayout以及所有其他透明区域将变为浅蓝色。当我填充这些EditTexts时,EditTexts周围屏幕的一些不可确定的部分会恢复它们的颜色。如果键盘出现时已经填充了EditTexts,则不会出现效果。
我花了几个小时来研究这个bug,寻找一个提示,但仍然不知道如何缩小范围。我希望我能给你更多的信息,但我不知道什么是相关的。
布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F2F2E5">
<RelativeLayout
android:id="@+id/extendedActionBar"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:background="#d8d8d8" >
<TextView
android:id="@+id/verbundenMit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:text="Verbunden mit:"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/DeviceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="165dp"
android:text="Device"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/fehlerbezeichnung"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="540dp"
android:text="Fehlerbezeichnung"
android:textAppearance="?android:attr/textAppearanceLarge"
android:visibility="gone" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:src="@drawable/rand_actionbar" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerVertical="true"
android:layout_marginLeft="740dp"
android:background="#ff0000"
android:src="@android:drawable/ic_dialog_alert"
android:visibility="gone" />
</RelativeLayout>
<Button
android:id="@+id/Parametersatzvergleich"
android:layout_width="180dp"
android:layout_height="80dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="80dp"
android:text="Vergleich: Online/Offline" />
<Button
android:id="@+id/NeuParameter"
android:layout_width="180dp"
android:layout_height="80dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="60dp"
android:layout_marginTop="80dp"
android:text="Neuer Parametersatz" />
<TextView
android:id="@+id/filter_bez"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="180dp"
android:text="Auswahlkriterien"
android:textAppearance="?android:attr/textAppearanceLarge" />
<FrameLayout
android:id="@+id/offlineframeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/filter_bez"
android:layout_marginBottom="25dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="80dp"
android:background="#d8d8d8" >
<ListView
android:id="@+id/offline_parameter_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#FFFCCC"
android:fadeScrollbars="false"
android:fastScrollEnabled="true" >
</ListView>
</FrameLayout>
<TextView
android:id="@+id/filterParameternummer_bez"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/filter_bez"
android:layout_marginLeft="25dp"
android:layout_marginTop="20dp"
android:text="Parameternr:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/filterParameternummer"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/filterParameternummer_bez"
android:layout_alignBottom="@+id/filterParameternummer_bez"
android:layout_marginLeft="140dp"
android:inputType="number" android:hint="...">
</EditText>
<Button
android:id="@+id/search"
android:layout_width="180dp"
android:layout_height="80dp"
android:layout_marginLeft="60dp"
android:layout_marginTop="80dp"
android:onClick="search"
android:text="Auswahl anwenden" />
<TextView
android:id="@+id/filterInfotext_bez"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Infotext:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginTop="20dp"
android:layout_below="@+id/filter_bez"
android:layout_marginLeft="250dp"/>
<EditText
android:id="@+id/filterInfotext"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:inputType="text"
android:layout_alignBaseline="@+id/filterInfotext_bez"
android:layout_alignBottom="@+id/filterInfotext_bez"
android:layout_marginLeft="320dp"
android:hint="..." android:focusable="true"
android:focusableInTouchMode="true"/>
</RelativeLayout>
活动
public final class OfflineParameterActivity extends AbstractBindingActivity implements OnClickListener {
private ArrayAdapter<ParameterSet> listAdapter;
public static final String EXTRA_DB_SOLLWERTE = "SollWerte";
private static final String TAG = MainActivity.class.getSimpleName();
private static final int REQUEST_PARAMETER_DETAILS = 100;
private static final int REQUEST_BLUETOOTH_ENABLE = 100;
private static final int REQUEST_BLUETOOTH_DEVICES = 101;
private Button parameterSatzVergleich;
private Button neuerParameter;
private EditText filterparameternummer;
private EditText filterinfotext;
private int paramnummer;
private String infotext;
protected ListAdapter adapter;
DBHelper dbHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.offlineparameter);
this.dbHelper = DBHandler.getDBHelper();
// Eabar: Ereignisse ausblenden per default
findViewById(R.id.verbundenMit).setVisibility(View.GONE);
findViewById(R.id.DeviceName).setVisibility(View.GONE);
// Buttons
parameterSatzVergleich = (Button) findViewById(R.id.Parametersatzvergleich);
parameterSatzVergleich.setOnClickListener(this);
parameterSatzVergleich.setTextColor(-16777216);
if (getCommunicationService() == null){
parameterSatzVergleich.setTextColor(-3355444);//LTGRAY
}
neuerParameter = (Button) findViewById(R.id.NeuParameter);
neuerParameter.setOnClickListener(this);
filterparameternummer = (EditText) findViewById(R.id.filterParameternummer);
filterinfotext = (EditText) findViewById(R.id.filterInfotext);
Intent intent = new Intent();
intent.putExtra(EXTRA_DB_SOLLWERTE, true);
this.listAdapter = new ArrayAdapter<ParameterSet>(this, android.R.layout.simple_list_item_2, android.R.id.text1) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {// Methode überschreiben
ParameterSet item = getItem(position);
View view = super.getView(position, convertView, parent);// Ergebnis der originalmethode holen
TextView textView1 = (TextView) view.findViewById(android.R.id.text1); // manipulieren
textView1.setText(getResources().getString(R.string.parameter_set_number, item.getParameterIndex() + 1));
TextView textView2 = (TextView) view.findViewById(android.R.id.text2);
if (!item.isEmpty()) {// Version mit "leer" bezeichnen
String temp = (getResources().getString(R.string.parameter_set_version, item.getVersion()));
String temp2 = (getResources().getString(R.string.parameter_set_infotext, item.getInfoText()));
textView2.setText(temp + " " + temp2);
}
else {
textView2.setText(R.string.parameter_set_empty);
}
return view;// zurückgeben
}
};
ListView listView = (ListView) findViewById(R.id.offline_parameter_list);
listView.setAdapter(this.listAdapter);
try {
List<ParameterSet> parameterSets = this.dbHelper.selectAllParameterSets();
OfflineParameterActivity.this.listAdapter.clear();
OfflineParameterActivity.this.listAdapter.addAll(parameterSets); // Alle Parametersätze in den ArrayAdapter werfen
}
catch (Exception e) {
Log.e(TAG, "Error: Parameterliste nicht erstellt", e);
}
// TODO: ist kein Eintrag passend:leere Listview! listView.setEmptyView(layout.findViewById(android.R.id.empty));
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ParameterSet parameter = (ParameterSet) parent.getItemAtPosition(position);
Intent intent = new Intent(OfflineParameterActivity.this, ParameterDetailsActivity.class);
intent.putExtra(ParameterDetailsActivity.EXTRA_PARAMETER_ID, parameter.getID());
String source = "offline_db";
intent.putExtra(ParameterDetailsActivity.EXTRA_URSPRUNGSACTIVITY, source);
startActivityForResult(intent, REQUEST_PARAMETER_DETAILS);
}
});
// Parameternummer Text verändert
this.filterparameternummer.addTextChangedListener(new AbstractTextWatcher() {
@Override
public void afterTextChanged(Editable s) {
OfflineParameterActivity.this.listAdapter.clear();
}
});
}
public void search(View view) {
// hide Keyboard
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(filterparameternummer.getWindowToken(), 0);
try {
// Parameternummer filtern
String nummer = filterparameternummer.getText().toString();
if (nummer.equals("")) {
this.paramnummer = -1;
}
else {
this.paramnummer = Integer.parseInt(nummer)-1;
}
// Infotext
this.infotext = filterinfotext.getText().toString();
// Parametersätze auswählen
List<ParameterSet> parameterSets = this.dbHelper.selectAllParameterSets(this.paramnummer, this.infotext);
OfflineParameterActivity.this.listAdapter.clear();
OfflineParameterActivity.this.listAdapter.notifyDataSetChanged();
OfflineParameterActivity.this.listAdapter.addAll(parameterSets); // Alle Parametersätze in den ArrayAdapter werfen
}
catch (Exception e) {
Log.e(TAG, "Error weil ebbes net gut isch", e);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_PARAMETER_DETAILS) {
finish();
}
else {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_BLUETOOTH_ENABLE && resultCode == RESULT_OK) {
startBluetoothDevicesActivity();
}
if (requestCode == REQUEST_BLUETOOTH_DEVICES && resultCode == RESULT_OK) {
final BluetoothDevice device = data.getParcelableExtra(EXTRA_BLUETOOTH_DEVICE);
Log.d(TAG, "Selected bluetooth device " + device);
Bundle extras = new Bundle(1);
extras.putParcelable(EXTRA_BLUETOOTH_DEVICE, device);
bindService(BluetoothService.class, extras);
}
}
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
super.onServiceConnected(name, service);
//EABAR
TextView deviceName = (TextView) findViewById(R.id.DeviceName);
deviceName.setText(getCommunicationService().getConnectedDeviceName());
findViewById(R.id.verbundenMit).setVisibility(View.VISIBLE);
findViewById(R.id.DeviceName).setVisibility(View.VISIBLE);
}
@Override
public void onServiceDisconnected(ComponentName name) {
super.onServiceDisconnected(name);
//EABAR: TODO: Wie bekomme ich mit wenn die Verbindung unterbrochen wird?
findViewById(R.id.verbundenMit).setVisibility(View.GONE);
findViewById(R.id.DeviceName).setVisibility(View.GONE);
}
// --------------------------------------------------------------------------------
// ActionBar / Menü
// --------------------------------------------------------------------------------
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.offlineparameter_menu, menu);
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
boolean isConnected = getCommunicationService() != null;
if (isConnected) {
setTitle("T12 Control - Offlineparameter - ONLINE");
}
else {
setTitle("T12 Control - Offlineparameter");
}
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
default:
return super.onOptionsItemSelected(item);
}
}
private void startBluetoothDevicesActivity() {
Intent intent = new Intent(this, BluetoothDevicesActivity.class);
startActivityForResult(intent, REQUEST_BLUETOOTH_DEVICES);
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.Parametersatzvergleich) {
if (v == parameterSatzVergleich) {
if (getCommunicationService() == null){
Toast.makeText(this, "zuerst Verbindung zur T12 aufbauen", Toast.LENGTH_LONG).show();
}
else{
//TODO: Vergleich
}
}
}
if (v.getId() == R.id.NeuParameter) {
if (v == neuerParameter) {
if (filterparameternummer.getText().toString().equals("")) {
Toast.makeText(this, "Parameternummer auswählen", Toast.LENGTH_LONG).show();
}
else {
int temp = Integer.parseInt(filterparameternummer.getText().toString());
if ( temp < 101 && temp > 0 ) {
Intent intent = new Intent(OfflineParameterActivity.this, ParameterDetailsActivity.class);
intent.putExtra(ParameterDetailsActivity.EXTRA_PARAMETER_INDEX, Integer.parseInt(filterparameternummer.getText().toString()) - 1 );
intent.putExtra(ParameterDetailsActivity.EXTRA_URSPRUNGSACTIVITY, "offline_neu");
startActivity(intent);
}
else {
Toast.makeText(this, "zulässige Parameternummern von 1 bis 100 ", Toast.LENGTH_LONG).show();
}
}
}
}
}
private static abstract class AbstractTextWatcher implements TextWatcher {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// Interessiert uns nicht
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// Interessiert uns nicht
}
}
}
答案 0 :(得分:0)
将android:cacheColorHint属性添加到ur listview
android:cacheColorHint="@android:color/transparent"
答案 1 :(得分:0)
将cacheColorHint属性设置为#00000000到列表视图 android:cache Color Hint =“#00000000”
答案 2 :(得分:0)
尝试:
listView.setSelector(android.R.color.transparent);
希望它有所帮助。