我无法启动我的Activity
,应用程序部队关闭,有关无法充气FAB
的错误,我已经阅读了针对某些问题提供的其他答案,但大多数人都提到了从他们的xml更改背景tint属性,并提到其他人将compat属性添加到您的活动中,我已经完成了它们,但仍然收到错误。任何人都可以弄明白,我做错了。
错误记录
无法启动活动ComponentInfo {com.fayaz.pix / com.fayaz.pix.MainActivity}:android.view.InflateException:二进制XML文件行#24:二进制XML文件行#24:错误膨胀类android.support .design.widget.FloatingActionButton
activity_main.xml中
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.fayaz.pix.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
摇篮
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.fayaz.pix"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.google.firebase:firebase-core:9.6.0'
compile 'com.firebaseui:firebase-ui-database:0.6.1'
compile 'com.firebaseui:firebase-ui-storage:0.6.1'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.android.support:cardview-v7:23.1.0'
}
apply plugin: 'com.google.gms.google-services'
活动
public class MainActivity extends AppCompatActivity {
private RecyclerView mPostRV;
private FirebaseRecyclerAdapter<Post, PostViewHolder> mPostAdapter;
private DatabaseReference mPostRef;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
initialiseScreen();
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sendPosttoFirebase();
}
});
}
private void sendPosttoFirebase() {
Post post = new Post();
String UID = Utils.getUID();
post.setUID(UID);
post.setNumLikes(0);
post.setImageUrl("https://static.pexels.com/photos/36487/above-adventure-aerial-air.jpg");
mPostRef.child(UID).setValue(post);
}
private void initialiseScreen() {
mPostRV = (RecyclerView)findViewById(R.id.post_rv);
mPostRV.setLayoutManager(new LinearLayoutManager(MainActivity.this));
mPostRef = FirebaseDatabase.getInstance().getReference(Constants.POSTS);
setupAdapter();
mPostRV.setAdapter(mPostAdapter);
}
private void setupAdapter() {
mPostAdapter = new FirebaseRecyclerAdapter<Post, PostViewHolder>(Post.class, R.layout.item_layout,PostViewHolder.class, mPostRef) {
@Override
protected void populateViewHolder(PostViewHolder viewHolder, final Post model, int position) {
StorageReference storageReference = FirebaseStorage.getInstance().getReferenceFromUrl(model.getImageUrl());
Glide.with(MainActivity.this)
.using(new FirebaseImageLoader())
.load(storageReference)
.into(viewHolder.postIV);
viewHolder.setNumLikes(model.getNumLikes());
viewHolder.postLikes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateNumLikes(model.getUID());
}
});
}
};
}
private void updateNumLikes(String uid) {
mPostRef.child(uid).child(Constants.NUM_LIKES).runTransaction(new Transaction.Handler() {
@Override
public Transaction.Result doTransaction(MutableData mutableData) {
long num = (long) mutableData.getValue();
num++;
mutableData.setValue(num);
return Transaction.success(mutableData);
}
@Override
public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot) {
}
});
}
public static class PostViewHolder extends RecyclerView.ViewHolder {
public ImageView postIV, postLikes;
public TextView numLikes;
public PostViewHolder(View itemView) {
super(itemView);
postIV = (ImageView)itemView.findViewById(R.id.post_iv);
postLikes = (ImageView)itemView.findViewById(R.id.likes_iv);
numLikes = (TextView)itemView.findViewById(R.id.num_likes_tv);
}
public void setNumLikes(long num){
numLikes.setText(String.valueOf(num));`enter code here`
}
}
}
清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fayaz.pix">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
答案 0 :(得分:0)
我不知道它是否有效但您是否尝试用线性布局或相对布局包围所有xml代码?