Note that there are some explanatory texts on larger screens.

plurals
  1. POChange color of selected and pressed listView items
    primarykey
    data
    text
    <p>i am trying hard to customize my listview.</p> <p>I changed the background of the TextViews which are in the listView.</p> <pre><code>&lt;TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_list_item_txt" android:layout_width="match_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceListItemSmall" android:gravity="center_vertical" android:paddingLeft="16dp" android:paddingRight="16dp" android:textColor="#000" android:background="@drawable/list_selector_orange" android:minHeight="?android:attr/listPreferredItemHeightSmall"/&gt; </code></pre> <p>Then i created the list_selector_orange in the drawable folder</p> <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android" &gt; &lt;item android:state_pressed="true" android:drawable="@drawable/selector_press_orange"/&gt; &lt;item android:state_selected="true" android:drawable="@drawable/selector_focus_orange" /&gt; </code></pre> <p></p> <p>If i press the button, it works:</p> <pre><code> &lt;shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" &gt; &lt;gradient android:angle="270" android:endColor="#FE9A2E" android:startColor="#FE9A2E" /&gt; &lt;/shape&gt; </code></pre> <p>But the currently selected item isnt colored anyway...</p> <pre><code>&lt;shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" &gt; &lt;gradient android:angle="90" android:endColor="#FF8000" android:startColor="#FF8000" /&gt; &lt;/shape&gt; </code></pre> <p>edit: Here is the code of the listview The XML-File... The ListView is part of a navigation drawer</p> <pre><code>&lt;android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" /&gt; &lt;ListView android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" android:background="#111" android:listSelector="@drawable/list_selector_orange" /&gt; </code></pre> <p></p> <p>This is the code of the Listener</p> <pre><code>private class DrawerItemClickListener implements ListView.OnItemClickListener { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { selectItem(position); } } private void selectItem(int position) { // update the main content by replacing fragments if(fragment != null){ //fragmentManager.beginTransaction().remove(fragment).commit(); } Bundle args; switch(position){ case 1: fragment = new de.sebspr.app08.viewpager.PagerFragment(); args = new Bundle(); args.putInt(de.sebspr.app08.viewpager.PagerFragment.ARG_PLAYER_NUMBER, position); fragment.setArguments(args); break; case 2: fragment = new de.sebspr.app08.viewpager.PagerFragment(); args = new Bundle(); args.putInt(de.sebspr.app08.viewpager.PagerFragment.ARG_PLAYER_NUMBER, position); fragment.setArguments(args); break; case 4: fragment = new de.sebspr.app08.halle.FragHalle(); break; } fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); setTitle(mListTitles[position].getTitle()); mDrawerLayout.closeDrawer(mDrawerList); } </code></pre> <p>I just chose a custom adapter because i want to have section headers. So i created one item wich is clickable and one which isn't</p> <pre><code>public View getView(int position, View convertView, ViewGroup parent){ Item item = items[position]; ViewHolder holder; if(convertView == null){ holder = new ViewHolder(); if(item.isSection()){ convertView = inflater.inflate(R.layout.drawer_list_section, null); holder.txt = (TextView) convertView.findViewById(R.id.drawer_list_section_txt); convertView.setLongClickable(false); convertView.setClickable(false); convertView.setOnClickListener(null); tFace = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-BoldCondensed.ttf"); holder.txt.setTypeface(tFace); convertView.setTag(holder); } else { convertView = inflater.inflate(R.layout.drawer_list_item, null); holder.txt= (TextView) convertView.findViewById(R.id.drawer_list_item_txt); tFace = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Regular.ttf"); holder.txt.setTypeface(tFace); convertView.setTag(holder); } } else { holder = (ViewHolder) convertView.getTag(); } holder.txt.setText(item.getTitle()); return convertView; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload