简体   繁体   中英

ListView in SYSTEM_ALERT_WINDOW

I'am trying to create a System Alert Windows that contain a listView. But I have some problems. I can see that there is items in the listview but I can not read the text and nothing happens if I click on the items. Let me add some pictures of the issue. 在此处输入图片说明

As you see in the first picture no items is showing but when showing layout bounds we can see that there is 2 items in the list.

    ListView lw = new ListView(this);
    String[] stringArray = new String[] { "Bright Mode", "Normal Mode" };
    ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, stringArray);
    lw.setAdapter(modeAdapter);
    layout.addView(lw);

This is how I created the list.

edit

I solved the visibility issue but I have still some issues with clicking on items in the list. The strange thing is that it works on a samsung galaxy note but not on any other device. This is my click logic.

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Log.v("head", "click");
        }
    });

I suggest you do something like this:

String[] stringArray = new String[] { "Bright Mode", "Normal Mode" };
listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, stringArray ) {
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView textView = (TextView) super.getView(position, convertView, parent);

        String text = stringArray [position];
        textView.setTextColor(Color.BLACK);
        return textView;
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM