标签: android-xml

String.xml或Constants类

在设计Android应用程序时,以下更好的方法是什么?

  1. 将所有String常量放在res/values/Strings.xml 或中
  2. 创建一个类似Constant.java所有字符串的类public static final

选择哪一个更有效?

android android-xml

24
推荐指数
1
解决办法
5693
查看次数

'找不到样式mapViewStyle'错误仍然存​​在

我刚刚决定在几天前休息时,我已经在这个应用程序上工作了近一年(高级项目).我的应用程序是使用我的Windows 7 64位PC使用Eclipse版3.7.2 64bit定位Froyo Android 2.2开发的.到目前为止,我尝试过:

  • 重新排列清单文件中的uses-library标记
  • 重写map xml文件
  • 删除R.java文件并刷新
  • 将mapview元素放在布局中
  • 重新安装eclipse和android-sdk
  • 清理项目
  • 创建style.xml文件并引用它
  • 在实际设备上部署
  • 恢复到以前的代码

可能更多......

我的代码如下:gmap.xml

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0xMbgnc-el963gCdpl547hdkgXUILTskZr-T5uvg" // random key posted here
/>
Run Code Online (Sandbox Code Playgroud)

AndroidManifest.xml中

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.PubMe"
  android:versionCode="1"
  android:versionName="1.0">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-sdk android:minSdkVersion="8"/>


<application android:icon="@drawable/icon" android:label="@string/app_name">
    <uses-library android:name="com.google.android.maps" />
    <activity android:name=".PubMeActivity"
              android:label="@string/app_name"
              android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".MappingActivity"
              android:label="@string/app_name">
    </activity>

</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)

我非常感谢任何提前帮助.

java eclipse android google-maps android-xml

24
推荐指数
1
解决办法
1725
查看次数

资源数组

有没有办法在XML中定义一个元素是资源引用的数组?例如(它不起作用,但它解释了我想要的):

<integer-array name="actions_images">
    <item>@drawable/pencil</item>
    <item>@drawable/pencil</item>
    <item>@drawable/pencil</item>
    <item>@drawable/pencil</item>
    <item>@drawable/pencil</item>
    <item>@drawable/pencil</item>
</integer-array>
Run Code Online (Sandbox Code Playgroud)

string android android-xml android-resources

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

任务 ':app:mergeDebugResources' 执行失败,无法在源集中找到资源文件

每当我对项目中的 XML 文件进行任何更改并尝试运行它时,我都会收到此错误 -

任务“:app:mergeDebugResources”执行失败。java.lang.IllegalArgumentException:无法在源集中找到资源文件(D:Q\app\build\intermediates\merged-not-compiled-resources\debug\layout\notification_action.xml)。

为了运行项目,每次对 XML 进行任何更改时,我都需要执行“构建”>“清理项目”。

以下是我的成绩档案 -

plugins {
    id 'com.android.application'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "xxxxx"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        debug {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.6.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation …
Run Code Online (Sandbox Code Playgroud)

android android-xml

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

Android:将xml包含在其他xml中

如何将xml数据包含到其他xml数据中

我有一个标题xml文件为我的应用程序我想在我的特殊其他内容使用xmls有没有办法将标题包含在我的内容中?

xml android android-xml

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

Android导航栏大小以xml为单位

有没有办法在xml文件中获取android中的导航栏大小?

 android:paddingTop="?android:attr/actionBarSize"
Run Code Online (Sandbox Code Playgroud)

哪里actionBarSize是导航栏大小?

android android-layout android-xml

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

添加自定义布局到工具栏

我按照本教程给我的应用程序一个带有一些标签的常规工具栏.

我想更改工具栏,使其看起来更像这样:

在此输入图像描述

我想在工具栏中添加一些文本和图像.我怎样才能做到这一点?

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:elevation="0dp">

        <android.support.v7.widget.Toolbar
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/primary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:theme="@style/ToolbarTheme"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabTextAppearance="@style/TabLayout"
            app:tabSelectedTextColor="@color/white"
            />

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        />

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

android android-layout android-xml

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

XmlPullParserException二进制XML文件行#17 <vector>标记需要viewportWidth> 0

这是对这个问题的后续问题:

将Android支持库更新到23.2.0会导致错误:XmlPullParserException二进制XML文件行#17 <vector>标记需要viewportWidth> 0

我还将支持库更新到23.2并开始收到错误:

XmlPullParserException Binary XML file line #17<vector> tag requires viewportWidth > 0
Run Code Online (Sandbox Code Playgroud)

这个问题解决了Android Studio和Gradle的问题.在没有Gradle的情况下使用Eclipse时如何解决这个问题?

android android-xml android-xmlpullparser

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

Android:最佳XML解析库?

我必须在我的Android应用程序中解析一些复杂的xml文件.像TouchXMl for iPhone那样有没有好的库?

xml android android-xml

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

如何向自定义属性添加文档?

我知道如何为视图创建自定义属性,例如:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="SomeViewsCustomAttrs">
        <attr name="someAttr" format="dimension" />
        <attr name="anotherAttr" format="boolean" />
    </declare-styleable>
</resources>    
Run Code Online (Sandbox Code Playgroud)

我想知道是否有办法向这些自定义attrs添加文档.在XML编辑器中编辑布局时,您可以获得描述attrs内容的工具提示.例如,如果您键入android:layout_width=它,它将为您提供以下信息,"指定视图的基本宽度.[dimension,enum]"

有没有办法为你自己的attrs提供?

谢谢

xml android attr android-xml

20
推荐指数
2
解决办法
1018
查看次数