小编LeD*_*Don的帖子

Android V7支持库弹出菜单

我正在尝试使用Support V7 Library实现PopupMenu.所有编译都很好但是当我试着打电话时:

    PopupMenu popup = new PopupMenu(this, v);
    popup.getMenu().add(Menu.NONE,MENU_SHARE_A,1,R.string.A);
    popup.getMenu().add(Menu.NONE,MENU_SHARE_B,2,R.string.B);
    popup.show();
Run Code Online (Sandbox Code Playgroud)

通话时出错:

07-31 17:23:53.365:E/AndroidRuntime(14128):java.lang.RuntimeException:二进制XML文件行#17:您必须提供layout_height属性.

使用这个元素我认为是"abc_popup_menu_item_layout.xml":

<android.support.v7.internal.view.menu.ListMenuItemView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="?attr/dropdownListPreferredItemHeight"
        android:minWidth="196dip"
        android:paddingRight="16dip">
Run Code Online (Sandbox Code Playgroud)

这是一个错误还是我做错了什么?

android android-support-library

13
推荐指数
2
解决办法
9637
查看次数

基于状态的ImageButton图标着色

我目前正在尝试使用当前纯白色的Drawables在某些ImageButton上实现着色。色调颜色应由StateList提供,并应根据按钮的当前状态进行更改。状态列表看起来像:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="#FF0000"/>
    <item android:color="#00FF00" android:state_enabled="false"/>
    <item android:color="#0000FF" android:state_pressed="true" android:state_enabled="true"/>
</selector>
Run Code Online (Sandbox Code Playgroud)

该按钮的布局XML代码段为:

<ImageButton
    android:id="@+id/btnNext"
    style="@style/Widget.AppCompat.Button.Borderless"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="@dimen/vertical_content_padding"
    android:layout_marginEnd="@dimen/horizontal_content_padding"
    android:contentDescription="@string/next"
    android:src="@drawable/ic_chevron_right_white_24dp"
    android:tint="@color/state_btn_tint_light"/>
Run Code Online (Sandbox Code Playgroud)

选择并正确显示了颜色状态列表中的默认色调。但是禁用或按下按钮不会在所有Icon上触发任何颜色更改。我也尝试使用setImageTintList实用地设置它。

android

5
推荐指数
1
解决办法
739
查看次数

NoSuchMethodError Bundle.getString()

我得到了一些奇怪的日志,这显然只发生在版本低于3的Android设备上(使用模拟器检查).当您更改方向时,使用非空的Bundle调用onCreate()或onRestoreInstanceState()时它会崩溃

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_menu);}
    if (savedInstanceState != null) {
        mSlug = savedInstanceState.getString(KEY_SLUG, null);
    }
}@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putString(KEY_SLUG, mSlug);
}@Override
protected void onRestoreInstanceState(Bundle outState) {
    super.onRestoreInstanceState(outState);
    if (outState != null) {
        mSlug = outState.getString(KEY_SLUG, mSlug);
    }
}
Run Code Online (Sandbox Code Playgroud)

LogCat-Log看起来像:http: //i.stack.imgur.com/WbivQ.png 有人知道这里发生了什么吗?

android

3
推荐指数
1
解决办法
2555
查看次数

房间Rxjava Single作为删除响应

我正面临房间库中编译时错误的一些问题.

我正在使用版本:2.1.0-alpha02

以下Dao导致错误:

@Dao()
public interface WorkoutExerciseDao {

    [......]
    @Update()
    Single<Integer> updateWorkout(final WorkoutExercise... workoutExercises);


    @Delete
    Single<Integer> deleteWorkouts(final WorkoutExercise... user);

    @Query("DELETE FROM workout_exercise_table WHERE id  IN(:exerciseIds)")
    Single<Integer> deleteWorkouts(final long... exerciseIds);
}
Run Code Online (Sandbox Code Playgroud)

目前,第一个@Delete带注释的方法编译正常并按预期工作.如果我添加第二个(在查询方法中删除),它会中断编译并出现错误:

删除方法必须返回void或return int(删除的行数).

我在这里想念一下吗?

android android-room

2
推荐指数
1
解决办法
663
查看次数

ListView使用多种类型的视图进行回收

我目前正在开发一个非常简单的ListView,最多有两种不同的视图类型.为了使一切顺利,我尝试回收视图.我的代码现在是:

@Override
public int getItemViewType (int position){
    if(mHasBefore&&position==0){
        return TYPE_PAGER;
    }else if(mHasNext&&position==getCount()-1){
        return TYPE_PAGER;
    }else return TYPE_SCORE;
}
@Override
public int getViewTypeCount (){
    return 1+((mHasBefore==true||mHasNext==true)?1:0);
}@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Log.d("outa","View: pos: "+position+ " . "+getItemViewType(position)+" - "+getViewTypeCount());
    if(getItemViewType(position)==TYPE_SCORE)return getScoreView(position,convertView,parent);
    else return getPagerView(position,convertView,parent);
}
protected View getPagerView(int position,View convertView,ViewGroup parent){
    if (convertView == null){
        convertView = LayoutInflater.from(parent.getContext()).inflate(
                R.layout.listitem_highscore_pager, null);}}
protected View getScoreView(int position,View convertView,ViewGroup parent){
    if (convertView == null){
        convertView = LayoutInflater.from(parent.getContext()).inflate(
                R.layout.listitem_highscore, null);}}
Run Code Online (Sandbox Code Playgroud)

基本上它应该在最后一个项目上显示不同的视图,但它仍然显示默认项目,即使LogCat声明它在getView()中不是TYPE_SCORE.因此convertView确实提供了回收视图.我做错了什么或者这是正常行为吗?

android listview

1
推荐指数
1
解决办法
2482
查看次数