单击TextView超过3次,应用程序崩溃

时间:2017-08-21 09:02:01

标签: android textview relativelayout crash-reports android-logcat

TextViews内有2 RelativeLayout。我已将clickable=true添加到RelativeLayout,以便点击RelativeLayout时,TextViews都会突出显示。我没有为Intent设置RelativeLayout。当我点击一次时,它没有崩溃,但问题是,当我立即点击超过3次RelativeLayout时它崩溃了。 在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 CODE:

    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;
    }
}

3 个答案:

答案 0 :(得分:3)

您是否尝试过设置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可能会产生连锁反应

我希望这会对你有所帮助

答案 1 :(得分:0)

我建议更好地执行构建→重建项目

使用无效捕获并重新启动

答案 2 :(得分:0)

android:onClick="onCLick"

由于您的java没有任何名为OnClick的函数,请尝试删除此行。也许它会触发内部呼叫