点击 TextView 超过 3 次,App 崩溃
Click more than 3 times TextView, App gets crashed
我在RelativeLayout
里面有2个TextViews
。我已将 clickable=true
放到我的 RelativeLayout
中,这样当单击 RelativeLayout
时,两个 TextViews
都会突出显示。我没有为我的 RelativeLayout
设置 Intent
。当我单击一次时,它没有崩溃,但问题是,当我 立即 单击 RelativeLayout 超过 3 次时,它崩溃了。
在 LogCat 中写着:E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
有人遇到过这样的问题并修复了吗?
我的 XML 文件:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="127dp"
android:background="#EEEEEE"
android:clickable="true">
<TextView
android:id="@+id/txt_ne_ne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginStart="70dp"
android:text="@string/qayerdan"
android:textSize="12sp"
android:layout_marginTop="10dp"
android:textColor="@color/light_dark"/>
<TextView
android:id="@+id/txt_qayerdan_tanlash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tanlash"
android:clickable="true"
android:textColor="@color/black"
android:layout_below="@+id/txt_ne_ne"
android:layout_marginLeft="70dp"
android:layout_marginStart="70dp"
android:layout_marginTop="1dp"
android:textSize="19sp" />
<TextView
android:id="@+id/txt_ne_ne2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginStart="70dp"
android:text="@string/qayerga"
android:clickable="true"
android:onClick="onCLick"
android:textSize="12sp"
android:layout_below="@id/txt_ne_ne"
android:layout_marginTop="40dp"
android:textColor="@color/light_dark"/>
<TextView
android:id="@+id/txt_qayerdan_tanlash2"
android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tanlash1"
android:textColor="@color/black"
android:layout_below="@+id/txt_ne_ne2"
android:layout_marginLeft="70dp"
android:layout_marginStart="70dp"
android:layout_marginTop="1dp"
android:textSize="19sp" />
JAVA 代码:
public class DelHome extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_del_h);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.post(new Runnable() {
@Override
public void run() {
Drawable d = ResourcesCompat.getDrawable(getResources(), R.drawable.menu, null);
toolbar.setNavigationIcon(d);
}
});
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.nav_buyurt_yar) {
} else if (id == R.id.nav_bosh_sahifa) {
} else if (id == R.id.nav_call_centre) {
} else if (id == R.id.nav_biz_haqimizda) {
} else if (id == R.id.nav_foyd_shartlar) {
} else if (id == R.id.nav_chiqish) {
System.exit(0);
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
我建议 Better to Perform Build → Rebuild 项目
或
使用无效捕获并重新启动
android:onClick="onCLick"
由于您的 java 没有任何名为 OnClick 的函数,请尝试删除此行。可能会触发内部调用
您尝试过设置 RelativeLayout
的背景吗?像这样:
在可绘制资源中创建 background_ripple.xml :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/grey_light"/>
</shape>
</item>
<item android:state_pressed="false">
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white"/>
</shape>
</item>
</selector>
并在您的 RelativeLayout
中进行设置
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="127dp"
android:background="@drawable/background_ripple"
android:clickable="true">
</RelativeLayout>
编辑:像这样,Android可能会产生连锁反应
希望对您有所帮助
我在RelativeLayout
里面有2个TextViews
。我已将 clickable=true
放到我的 RelativeLayout
中,这样当单击 RelativeLayout
时,两个 TextViews
都会突出显示。我没有为我的 RelativeLayout
设置 Intent
。当我单击一次时,它没有崩溃,但问题是,当我 立即 单击 RelativeLayout 超过 3 次时,它崩溃了。
在 LogCat 中写着:E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
有人遇到过这样的问题并修复了吗?
我的 XML 文件:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="127dp"
android:background="#EEEEEE"
android:clickable="true">
<TextView
android:id="@+id/txt_ne_ne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginStart="70dp"
android:text="@string/qayerdan"
android:textSize="12sp"
android:layout_marginTop="10dp"
android:textColor="@color/light_dark"/>
<TextView
android:id="@+id/txt_qayerdan_tanlash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tanlash"
android:clickable="true"
android:textColor="@color/black"
android:layout_below="@+id/txt_ne_ne"
android:layout_marginLeft="70dp"
android:layout_marginStart="70dp"
android:layout_marginTop="1dp"
android:textSize="19sp" />
<TextView
android:id="@+id/txt_ne_ne2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginStart="70dp"
android:text="@string/qayerga"
android:clickable="true"
android:onClick="onCLick"
android:textSize="12sp"
android:layout_below="@id/txt_ne_ne"
android:layout_marginTop="40dp"
android:textColor="@color/light_dark"/>
<TextView
android:id="@+id/txt_qayerdan_tanlash2"
android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tanlash1"
android:textColor="@color/black"
android:layout_below="@+id/txt_ne_ne2"
android:layout_marginLeft="70dp"
android:layout_marginStart="70dp"
android:layout_marginTop="1dp"
android:textSize="19sp" />
JAVA 代码:
public class DelHome extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_del_h);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.post(new Runnable() {
@Override
public void run() {
Drawable d = ResourcesCompat.getDrawable(getResources(), R.drawable.menu, null);
toolbar.setNavigationIcon(d);
}
});
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.nav_buyurt_yar) {
} else if (id == R.id.nav_bosh_sahifa) {
} else if (id == R.id.nav_call_centre) {
} else if (id == R.id.nav_biz_haqimizda) {
} else if (id == R.id.nav_foyd_shartlar) {
} else if (id == R.id.nav_chiqish) {
System.exit(0);
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
我建议 Better to Perform Build → Rebuild 项目
或
使用无效捕获并重新启动
android:onClick="onCLick"
由于您的 java 没有任何名为 OnClick 的函数,请尝试删除此行。可能会触发内部调用
您尝试过设置 RelativeLayout
的背景吗?像这样:
在可绘制资源中创建 background_ripple.xml :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/grey_light"/>
</shape>
</item>
<item android:state_pressed="false">
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white"/>
</shape>
</item>
</selector>
并在您的 RelativeLayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="127dp"
android:background="@drawable/background_ripple"
android:clickable="true">
</RelativeLayout>
编辑:像这样,Android可能会产生连锁反应
希望对您有所帮助