标签: android-xml

Android无法解析符号'?attr/selectableItemBackground'

<android.support.v7.widget.CardView
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/card_outer_padding"
    android:layout_marginTop="@dimen/card_outer_padding"
    android:layout_marginRight="@dimen/card_outer_padding"
    android:layout_marginBottom='@{model.cardBottomMargin}'
    android:foreground="?attr/selectableItemBackground"
    android:onClick="@{model::onCardClick}"
    app:cardElevation="2dp"
    app:cardCornerRadius="2dp"
    app:cardUseCompatPadding="true">
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

我收到此错误消息

无法解析符号?attr/selectableItemBackground 验证Android XML文件中的资源引用.

<TextView
    android:id="@+id/country_name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginRight="40dp"
    android:text="@{model.name}"
    style="@style/TextAppearance.AppCompat.Headline"
    tools:text="Country"/>
Run Code Online (Sandbox Code Playgroud)

而且,我也遇到了类似的错误

无法解析符号'@ style/TextAppearance.AppCompat.Headline'
验证Android XML文件中的资源引用.

任何指针都会很棒!谢谢!它似乎与此线程有关,但没有提供解决方案:

android android-xml

54
推荐指数
4
解决办法
2万
查看次数

如何更改"使用Facebook登录"按钮的高度?

我已经尝试了几个我能找到的答案,但没有一个能与最新的Facebook Android SDK 4.0一起使用.

如何使用最新的SDK更改布局高度?

android facebook android-xml facebook-login facebook-sdk-4.0

52
推荐指数
2
解决办法
3万
查看次数

为标记LinearLayout找到了意外的名称空间前缀"xmlns"

我在跟踪xml文件时出错."为标记LinearLayout找到"意外的名称空间前缀"xmlns".我尝试了其他类似问题中提供的解决方案,但它对我不起作用.在使用的3行中发生相同的错误LinearLayout.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/background" >

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/menu_top_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/name_version"
            android:textColor="@color/black"
            android:textSize="20sp" />

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

        <!-- A horizontal line -->

        <FrameLayout
            android:layout_width="fill_parent"
            android:layout_height="30px" >
        </FrameLayout>

        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:orientation="vertical" >

            <LinearLayout
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="horizontal" >

                <Button
                    android:id="@+id/start_stop_button"
                    android:layout_width="74dp"
                    android:layout_height="74dp"
                    android:text="@string/start_server" />

                <Button
                    android:id="@+id/instructions"
                    android:layout_width="120dp"
                    android:layout_height="74dp"
                    android:text="@string/instructions_label" />

                <Button
                    android:id="@+id/setup"
                    android:layout_width="74dp"
                    android:layout_height="74dp"
                    android:text="@string/setup_label" />
            </LinearLayout>
        </LinearLayout>

        <FrameLayout
            android:layout_width="fill_parent" …
Run Code Online (Sandbox Code Playgroud)

xml eclipse android android-xml

51
推荐指数
3
解决办法
6万
查看次数

从Plurals获取字符串以在XML中使用?

我正在使用Plurals来简化我的代码.例如,我曾经有过

<string name="cat">Cat</string>
<string name="cats">Cats</string>
Run Code Online (Sandbox Code Playgroud)

我现在使用Plurals而不是多个字符串

<plurals name="cats">
    <item quantity="one">Cat</item>
    <item quantity="other">Cats</item>
</plurals>
Run Code Online (Sandbox Code Playgroud)

但是,我曾经检索过要在我的XML中用作标题或摘要的字符串.例如,

android:title="@string/cats"
Run Code Online (Sandbox Code Playgroud)

删除了该字符串以支持Plural,我现在不确定如何从XML中检索我的字符串.我做了一个天真的尝试

android:title="@plurals/cats"
Run Code Online (Sandbox Code Playgroud)

但这只是给了我@1234567890而不是Cats(或Cat).

有人知道是否可以从XML中检索Plural中的字符串?

android android-xml

51
推荐指数
5
解决办法
2万
查看次数

我想让我的应用程序只在android中的横向

我想让我的应用程序仅在横向模式下工作,但无法使其工作.我已经给出了screenOrientation = "landscape"即使第一页将处于横向模式,其他活动将是纵向的.

XML文件

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".Main"
              android:label="@string/app_name"
              android:screenOrientation="landscape" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>     

    </activity>

    <activity android:name=".IntroHome"
              android:label="@string/app_name"
              android:screenOrientation="landscape">
    </activity>

    <activity android:name=".ObjectivesPage"
              android:label="@string/app_name"
              android:screenOrientation="landscape" >
    </activity>

    <activity android:name=".MenuPage"
              android:label="@string/app_name"
              android:screenOrientation="landscape" >
    </activity>
</application>
Run Code Online (Sandbox Code Playgroud)

JAVA CLASS

public class ObjectivesPage extends Activity{

    ImageButton  imgButton;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.objectivespage);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

        imgButton = (ImageButton)findViewById(R.id.buttonCloseNGo);
        imgButton.setOnClickListener(onClickCloseNGo);
    }

    private OnClickListener onClickCloseNGo = new OnClickListener(){

        public void onClick(View v) {
            Intent intent = new Intent(ObjectivesPage.this,MenuPage.class);
            startActivity(intent); …
Run Code Online (Sandbox Code Playgroud)

android screen-orientation android-layout android-xml

49
推荐指数
1
解决办法
7万
查看次数

自定义设计EditText

我有自定义设计 EditText

在此输入图像描述

search_page.xml

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="10dp"
    android:background="#E1E1E1"
    android:weightSum="1" >

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".25"
        android:text="City" />

    <EditText
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:background="@drawable/rounded_edittext"
        android:layout_weight=".75" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

rounded_edittext.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:padding="10dp"
    android:shape="rectangle" >

    <solid android:color="#FFFFFF" />

    <corners
        android:bottomLeftRadius="10dp"
        android:bottomRightRadius="10dp"
        android:topLeftRadius="10dp"
        android:topRightRadius="10dp" />

</shape>
Run Code Online (Sandbox Code Playgroud)

我想使用颜色代码#2f6699获取边框颜色,如EditText文本框中的轮廓,如下所示:

在此输入图像描述

关于如何实现这一点的任何想法?

android android-xml android-edittext

43
推荐指数
2
解决办法
12万
查看次数

ImageView不保持最大高度和宽度

我将图像加载到从用户照片库中检索到的ImageView使用.setImageURI(selectedImageUri)中.我有图像视图限制大小

android:maxHeight="150dp"
android:minHeight="150dp" 
android:maxWidth="150dp" 
android:minWidth="150dp"
Run Code Online (Sandbox Code Playgroud)

在您从图库添加图像之前,这很好.然后图像会忘记最大高度和宽度.它与显示器一样宽,图像上方和下方有很多空间.我必须添加一个scrollview才能看到图像并向下滚动.上面和下面有一个均匀的空间.有没有人遇到过这个问题?

android android-layout android-xml android-imageview

41
推荐指数
1
解决办法
2万
查看次数

如何在Android上创建首选项活动和首选项片段?

当我关注一个旧教程(Créezdesapplications pour Android - > openclassroom)时,我addPreferencesFromResource(int id)从PreferenceActivity类中坚持使用这个弃用的方法.

所以我的问题是:

在Android中创建首选项的新方法是什么?

android android-preferences android-xml android-fragments android-activity

40
推荐指数
2
解决办法
6万
查看次数

使用多个string.xml文件是否有任何副作用?

我目前正在创建一个具有一些字符串的应用程序(现在> 300),我有一些问题可以快速找到包含这么多字符串的字符串.所以我在考虑使用多个string.xml文件而不是只有一个文件的可能性(string_menu,string_activity1,...).

这种做法有副作用吗?这是一个坏的还是一个好的做法?

我问这个是因为似乎网上没有多少人正在使用这种可能性.那么也许有一些问题呢?

string android android-xml

39
推荐指数
2
解决办法
1万
查看次数

如何在ScrollView android中更改实际滚动的颜色?

我想知道是否可以改变ScrollView的颜色.

我不是指背景颜色或边缘.
我附上了我所指的酒吧的打印屏幕.对我来说,这是透明的.

这是我在xml中定义它的方式:

<ScrollView  
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:fadeScrollbars="false"
    android:layout_toLeftOf="@+id/personalscores_BackButton" 
    android:layout_marginRight="0dp" > 
Run Code Online (Sandbox Code Playgroud)

滚动条

android scrollview android-layout android-xml

38
推荐指数
4
解决办法
3万
查看次数