【问题标题】:Adding Android Google PlusOneButton to layout causes compilation error将 Android Google PlusOneButton 添加到布局会导致编译错误
【发布时间】:2016-10-02 12:23:43
【问题描述】:

我想将 google+ 按钮添加到我的应用中。我遵循了这个指示: https://developers.google.com/+/mobile/android/recommend

我既不能实现类 PlusOneButton 也不能实现 xml-tag:<com.google.android.gms.plus.PlusOneButton/>

二进制 XML 文件第 31 行:二进制 XML 文件第 31 行:膨胀类 com.google.android.gms.plus.PlusOneButton 时出错

XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="16dp"
    android:paddingStart="16dp"
    android:paddingRight="16dp"
    android:paddingEnd="16dp"
    android:background="@color/primary_light"
    android:paddingTop="@dimen/custom_margin_top_bottom"
    android:paddingBottom="@dimen/custom_margin_top_bottom">

    <TextView
        android:id="@+id/nachrichtTv"
        android:layout_width="match_parent"
        android:layout_gravity="center"
        android:gravity="center"
        android:layout_height="wrap_content"
        android:textColor="@color/white"
        android:singleLine="true"
        android:ellipsize="marquee"
        />

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.google.android.gms.plus.PlusOneButton

            android:id="@+id/plus_one_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />


    </LinearLayout>

</LinearLayout>

【问题讨论】:

    标签: android button implementation


    【解决方案1】:

    你可以这样做:

    添加到 Gradle

    compile 'com.google.android.gms:play-services:7.3.0'
    

    向您的 layout.xml 添加按钮:

    <com.google.android.gms.plus.PlusOneButton
        xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
        android:id="@+id/plus_one_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        plus:size="standard"
        plus:annotation="inline" />
    

    最后在你的 Activity 中你有 PlusOneButton:

        PlusOneButton plusOneButton =(PlusOneButton) findViewById(R.id.plus_one_button);
    
        plusOneButton.initialize(URL, 0);
    

    【讨论】:

    • 如果我不喜欢按钮的设计并想使用普通按钮。如何添加行为?
    猜你喜欢
    • 2016-02-17
    • 1970-01-01
    • 2014-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-11
    • 1970-01-01
    • 2012-07-19
    相关资源
    最近更新 更多