默认情况下,android复选框显示右侧的文本和左侧的复选框
我想在右侧显示复选框,左侧显示文本
我怎么做到这一点?
我有一个简单的列表,其中包含listselector.
<ListView android:id="@+id/list" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_below="@+id/round"
android:listSelector="#99000000" android:clickable="true" android:cacheColorHint="#00000000" android:background="#00000000">
</ListView>
Run Code Online (Sandbox Code Playgroud)
如您所见,android:listSelector ="#99000000",但"黑色alpha"颜色应用于整个列表,而不是所选项目.
所以这就是我现在所拥有的,但整个列表仍然变黑
:: listview_background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:state_focused="true"
android:drawable="@drawable/list_normal" />
<item android:state_pressed="true"
android:drawable="@drawable/list_pressed" />
<item android:state_focused="true"
android:drawable="@drawable/list_active" />
</selector>
Run Code Online (Sandbox Code Playgroud)
:: colors.xml
<resources>
<drawable name="list_normal">#96FFFFFF</drawable>
<drawable name="list_active">#66000000</drawable>
<drawable name="list_pressed">#CA000000</drawable>
</resources>
Run Code Online (Sandbox Code Playgroud)
::我列表中的xml标记
android:listSelector="@drawable/listview_background"
Run Code Online (Sandbox Code Playgroud) 我ListView在我的布局中使用了这样的:
<ListView android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_gravity="center"
android:layout_height="match_parent"
android:layout_weight="0.7"
android:layout_marginTop="5dp"
android:orientation="vertical"
android:layout_centerInParent="true"
android:divider="@color/dark_grey"
android:drawSelectorOnTop="false"
android:focusable="true"
android:layout_marginBottom="55dp"
android:cacheColorHint="#00000000"
android:listSelector="@color/light_grey"
android:dividerHeight="1px" />
Run Code Online (Sandbox Code Playgroud)
选择器工作得很好,但如何禁用选择器?
我试过了:
listView.clearChoices();
listView.setSelected();
listView.setSelector();
...
Run Code Online (Sandbox Code Playgroud)
还有一些东西,但没有任何作用.我有什么想法可以将我选择的项目恢复正常吗?不能那么复杂吧?
编辑:我需要一个程序化的解决方案!
谢谢!
我正在尝试检测按钮和其他元素的焦点/按下颜色.这是必要的,因为我正在开发新组件,重要的是那些看起来像平台的一部分.这些颜色在Android sdk上是ORANGE,在HTC SenseUI上是GREEN.如果我能检测到这种颜色,我的组件将在两个版本上看作平台的一部分.
有谁知道怎么做?
可以创建"选择器",其使用自定义图像作为默认状态和平台默认值进行聚焦/选择.
要执行此操作,请按照以下步骤操作: 1)使用"res/drawable"中的选择器创建xml文件(例如"red_button.xml"):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@android:drawable/btn_default" >
</item>
<item android:state_focused="true"
android:drawable="@android:drawable/btn_default" >
</item>
<item
android:drawable="@drawable/btn_default_red" >
</item>
</selector>
Run Code Online (Sandbox Code Playgroud)
2)从文件夹".../android-sdk-mac/platforms/android-1.5/data/res/drawable /"拍照"btn_default_pressed.9.png"并根据需要改变颜色(我需要将其更改为红色,为此GIMP就足够了).
3)将改变的图片放在"res/drawable"中(例如,名称为"btn_default_red.9.png")
4)定义按钮:
<Button
android:id="@+id/info_button"
android:layout_width="wrap_content"
android:layout_height="37dip"
android:layout_marginTop="1dip"
android:background="@drawable/red_button"
android:text="[Info]" />
Run Code Online (Sandbox Code Playgroud)
就这样.
结果如下: alt text http://img200.imageshack.us/img200/1349/custombutton.png
有人能告诉我Holo中所选列表项的相应颜色代码吗?另外,在Holo中生成长按列表项目转换的颜色是什么?我知道Holo颜色是在colors.xml中定义的,但我不确定哪些用于选择和长按列表项转换.提前致谢.
我遇到了以下问题.
我有一个ListView,其自定义行包含imageview和textview.textview的xml代码是
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="26px"
android:layout_marginLeft="3px"
android:singleLine="true"
android:ellipsize="end"
android:textColorHighlight="#FEC403"
/>
Run Code Online (Sandbox Code Playgroud)
然后我有一个itemclicklistener工作正常,我想通过执行以下操作突出显示已单击的textview.
public void onItemClick(AdapterView<?> adaptview, View clickedview, int position,
long id) {
//TODO: ACTIONS
String pathtofile = (String) adaptview.getItemAtPosition(position);
View rowview = (View) adaptview.getChildAt(position);
rowview.setSelected(true);}
Run Code Online (Sandbox Code Playgroud)
我希望高亮颜色为xml中的"#FEC403"(浅橙色),但高亮颜色仍为灰色.那么如何正确设置高亮颜色?
提前致谢
编辑:
这是我最终如何做到的:
这是我的ListView Item xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/rowselector"
>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/musicicon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="@drawable/musicicon"
android:paddingLeft="3px"
/>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="26px"
android:layout_marginLeft="3px"
android:singleLine="true"
android:ellipsize="end"
android:focusable="false"
/>
Run Code Online (Sandbox Code Playgroud)
和rowselector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> …Run Code Online (Sandbox Code Playgroud) 我正在研究android应用程序,我能够使用ItemizedOverlay在地图上显示多个图标,并且我还实现了ItemizedOverlay的onTap(int index)方法,以在所需窗口中显示图标特定信息.
现在,我想在用户点击其他组合时更改所选叠加层的图标.我调用ItemizedOverlay的setFocus(OverlayItem)方法来显示特定叠加的不同图标.当用户点击任何特定的叠加层但在我调用setFocus(OverlayItem)方法时不会更改图标时,它可以正常工作.
有什么指针吗?在mapView中以编程方式更改所选叠加图标的最佳方法是什么?
我已经覆盖了我的自定义OverlayItem类的getMarker方法,以显示不同的overlayItem状态的不同标记.我想使用setFocus(OverlayItem)方法来更改OverlayItem的状态,并在选择时更改标记.
@Override
public Drawable getMarker(int stateBitset){
if(stateBitset==0){
icon = Util.getCategoryMapIcon(0);
icon.setBounds(0-icon.getIntrinsicWidth()/2, 0-icon.getIntrinsicHeight(), icon.getIntrinsicWidth()/2, 0);
return icon;
}else {
icon = Util.getCategoryMapIcon(OverlayItem.ITEM_STATE_SELECTED_MASK);
icon.setBounds(0-icon.getIntrinsicWidth()/2, 0-icon.getIntrinsicHeight(), icon.getIntrinsicWidth()/2, 0);
return icon;
}
}
Run Code Online (Sandbox Code Playgroud)
这里Util.getCategoryMapIcon(0)是返回相应图标的Utility方法,此方法需要一些参数,我已删除这些参数使这个例子看起来很简单.
以下是改变状态的代码
Button leftNavigation = (Button) findViewById(R.id.left_navigation_button);
leftNavigation.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
OverlayItem item = searchResultsOverlay.get(index+1);
setFocus(item);
}
});
Run Code Online (Sandbox Code Playgroud)
任何帮助都感激不尽.谢谢,Aamir
我正在使用RecyclerView来实现NavigationDrawer。
我可以使用点击事件,但是我无法弄清楚如何在App上启动第一个项目,然后如何使选定的项目保持高亮显示,即使未显示抽屉也是如此。
我所能找到的就是在RecyclerView中进行多选。
所以我在Android上有一个listView,我在代码中创建如下:
setListAdapter(new ArrayAdapter<String>(this, R.layout.menuitem, menuitems));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setBackgroundColor(Color.RED);
lv.setOnItemClickListener(new OnItemClickListener() { ... });
Run Code Online (Sandbox Code Playgroud)
有没有办法将代码中的选择颜色从默认的橙色更改为另一种颜色?
我试图在我的ListView上禁用ListView选择器.我将列表选择器颜色设置为透明颜色.这似乎可以解决问题,但是当我选择某些文本时,它们会改变颜色.我怎样才能使工作正常?
我知道我可以通过以下代码的一些变体动态设置ListView的背景颜色:
ListView mainListView;
mainListView = (ListView) findViewById( R.id.listView1 );
mainListView.setBackgroundColor(Color.BLACK);
Run Code Online (Sandbox Code Playgroud)
但是,我想通过XML做同样的事情.我试了下面的代码没有任何运气(它没有任何变化):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
**android:background="#FFFFFF"**
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
</ListView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
有谁知道通过XML更改ListView的背景颜色的简单方法?
我有一个listview,它有一个适配器,工作正常,但后来我添加了一些代码,因为我希望行是不同的颜色,之后,onclick颜色不会显示.
这是我添加的代码:
if (position % 2 == 0)
vi.findViewById(R.id.parentL).setBackgroundColor(ctx.getResources().getColor(R.color.row1));
else
vi.findViewById(R.id.parentL).setBackgroundColor(ctx.getResources().getColor(R.color.row2));
Run Code Online (Sandbox Code Playgroud)