全部工作演示
MainActivity
package pk.sohail.gallerytest.activity;
import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import pk.sohail.gallerytest.R;
public class MainActivity extends AppCompatActivity {
Context context;
private CoordinatorLayout coordinatorLayout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = this;
coordinatorLayout = (CoordinatorLayout) findViewById(R.id
.coordinatorLayout);
ImageView image = (ImageView) findViewById(R.id.myimage);
image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
Snackbar snackbar = Snackbar
.make(coordinatorLayout, "Message is deleted", Snackbar.LENGTH_LONG)
.setAction("UNDO", new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar snackbar1 = Snackbar.make(coordinatorLayout, "Message is restored!", Snackbar.LENGTH_SHORT);
snackbar1.show();
}
});
snackbar.show();
}
});
}
}
activity_main.xml中
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white">
<ImageView
android:id="@+id/myimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@mipmap/ic_launcher" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
風格:父= 「Theme.AppCompat.Light」
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<!--<item name="colorPrimary">@color/colorPrimary</item>-->
<!--<item name="colorPrimaryDark">@color/colorPrimaryDark</item>-->
<!--<item name="colorAccent">@color/colorAccent</item>-->
</style>
清單:在應用程序標記中設置主題爲@style/AppTheme
。
<application
...
android:theme="@style/AppTheme"
...
>
</application>
logcat please ??? ??? – Rahul
請把你的logcat –
你必須提供任何視圖給小吃店,這是非空。 – SANAT