标签: android-xml

Android菜单换行

我有以下Android菜单XML文件:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/programma"
          android:icon="@android:drawable/ic_menu_agenda"
          android:title="@string/programma" />
    <item android:id="@+id/settings"
          android:icon="@android:drawable/ic_menu_preferences"
          android:title="@string/settings" />
    <item android:id="@+id/help"
          android:icon="@android:drawable/ic_menu_help"
          android:title="@string/help" />
</menu>
Run Code Online (Sandbox Code Playgroud)

这给了我一行三个菜单按钮.但是,我想将它们分成两行,第一行有2个按钮,整个底行有帮助按钮.我已经尝试过对前两个进行分组,但这并没有成功.如何在XML中强制换行?

java xml android android-xml android-menu

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

有没有办法改变吐司的颜色和文字大小/颜色,但保留系统吐司布局?

我知道我可以使用自定义Toast布局轻松完成所有这些操作,但在创建自定义布局时,我将不再使用系统的默认Toast视图.

示例:Android 2.2与Android 4.0的Toast当然看起来不同.如果我为我的吐司创建一个自定义视图,那么它在两个版本中都会看起来完全相同,但我想要的是保留它的......"Androidiness",因为缺少一个更好的单词.基本上,有没有人知道默认的toast XML布局?这甚至可能吗?

android toast android-xml

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

选项菜单未出现在Android中

我有这个代码来创建菜单:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.tip_menu, menu);
    return true;

}


@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case MNU_PREV:
        animateTextViewsPrev();
        break;

    case MNU_NEXT:
        animateTextViewsNext();
        break;
    }

    return true;
}
Run Code Online (Sandbox Code Playgroud)

和XML:

<?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android" >
        <item android:id="@+id/prev_tip" android:title="@string/prevTip"></item>
        <item android:id="@+id/next_tip" android:title="@string/nextTip"></item>
    </menu>
Run Code Online (Sandbox Code Playgroud)

在具有Android 2.1的智能手机中,菜单是可见的,但在其他移动设备中,4.1.1是不可见的.有人现在该怎么解决呢?

android android-xml android-menu android-optionsmenu

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

Android工作室只是通过很多红线

我正在使用android studio,当我今天打开我的项目时

在此输入图像描述

我不知道我做了什么.昨天似乎很好,但我试图让谷歌地图工作.我知道这不是很多信息,所以如果有任何你认为你需要看到试图帮助我的东西,请告诉我.

android android-xml android-studio

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

UnknownFormatConversionException:Android strings.xml format <![CDATA [...%1 $ ...]]>

我正在尝试在strings.xml中使用格式化的html .所以在strings.xml中我有以下内容:

<string name="application_start_message" formatted="false">
    <![CDATA[ bla bla bla %1$ bla bla bla %1$.... ]]>
<string name="application_website_url">website.com</string>
Run Code Online (Sandbox Code Playgroud)

后来我在代码中做了:

String string = getString(
    R.string.application_start_message,
    getString(R.string.application_website_url)
);
Run Code Online (Sandbox Code Playgroud)

我得到的运行时异常是:

java.lang.RuntimeException: Unable to start activity 
    ComponentInfo{com.artigile.checkmyphone/
    com.artigile.checkmyphone.MainActivity}: 
    java.util.UnknownFormatConversionException: Conversion: <
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

Caused by: java.util.UnknownFormatConversionException: Conversion: <
at java.util.Formatter$FormatToken.unknownFormatConversionException(Formatter.java:1399)
at java.util.Formatter$FormatToken.checkFlags(Formatter.java:1336)
at java.util.Formatter.transform(Formatter.java:1442)
at java.util.Formatter.doFormat(Formatter.java:1081)
at …
Run Code Online (Sandbox Code Playgroud)

formatting android cdata android-xml

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

在Webview内单击文本开始活动意图

我在xml中有一个webview,如下所示:

 <WebView
        android:id="@+id/webView"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
Run Code Online (Sandbox Code Playgroud)

我正在加载这样的webview:

String webView_text = "Lorem ipsum..............**<a><u>Link to fire intent</u></a>**";

 WebView webView= (WebView) findViewById(R.id.webView);
webView.loadData(String.format(htmlText, webView_text), "text/html", "utf-8");
        webView.setWebViewClient(new WebViewClient()
        {
            // Override URL
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                Intent intent = new Intent(getApplicationContext(),OtherActivity.class);
                startActivity(intent);
                return true;
            }
        });
Run Code Online (Sandbox Code Playgroud)

请注意,我正在使用html标签在字符串(webView_text)中创建链接,并且覆盖了该函数以激发意图。在这种情况下不这样做。这里有什么问题?我不确定Android Webview是否支持该标签(我认为应该支持)。我的错在这里。先谢谢您。

android android-intent android-webview android-xml android-activity

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

Android RelativeLayout在另一个元素边框上对齐元素

我试图使文本视图与RelativeLayout中另一个imageview的左边框对齐,但我遇到了麻烦,我无法实现这一点.任何人都可以告诉我如何实现这一目标?

在此输入图像描述

在此输入图像描述

这是我当前的XML布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="15dp"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/main_item_bg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:contentDescription="@string/app_name"
        android:scaleType="fitXY" />

    <RelativeLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@drawable/blackalha"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:weightSum="100" >

        <TextView
            android:id="@+id/main_item_cont"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_centerVertical="true"
            android:layout_toLeftOf="@+id/main_item_nmb"
            android:paddingLeft="5dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/white" />

        <ImageView
            android:id="@+id/main_item_ic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:background="@color/app_purple"
            android:src="@drawable/bacal" />

        <TextView
            android:id="@+id/main_item_nmb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_toLeftOf="@+id/main_item_ic"
            android:background="@drawable/saric"
            android:gravity="center"
            android:textColor="#333333" />

    </RelativeLayout>

    <TextView
        android:id="@+id/main_item_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignTop="@+id/main_item_bg"
        android:layout_margin="5dp"
        android:maxWidth="200dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@android:color/white" />

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

android android-layout android-xml

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

我如何在Android XML布局文件中使用View节点?

在Android Studio中,我看到了一个<View />节点,它具有Widget的所有属性.我很好奇,这个节点是什么,我怎么能用呢?

<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="@color/material_cyan_200"
 />
Run Code Online (Sandbox Code Playgroud)

xml android android-xml android-view

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

进度条在按钮中间

我想标准按钮的中间创建一个进度条,如下所示: 进度条

在xml布局中,当我点击进度条时,我确实看到它位于我希望它的位置,但实时,我看不到它,感觉就像隐藏在按钮下方. android studio xml

我试过了 :

  1. 更改视图的位置(进度条上方/下方的按钮)
  2. 不定
  3. 玩ProgressBar的风格

似乎没有什么工作.

这是我的xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/button_id"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:elevation="1dp"
        android:text="test button" />

    <ProgressBar
        android:id="@+id/progress"
        style="?android:attr/progressBarStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/button_id"
        android:layout_alignTop="@+id/button_id"
        android:layout_centerHorizontal="true"
        android:indeterminate="true"
        android:indeterminateTint="@android:color/holo_blue_dark"
        android:visibility="visible" />

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

android android-layout android-progressbar android-xml android-button

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

如何在底部使Button重叠CardView

我正在创建一个显示公告的应用程序,我想添加一个登录信息.我正在尝试制作这个XML设计,图片.我想按钮OVERLAP在底部,它的中心CardView.如果有必要,我将更改文件的根目录.

这是我的XML代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:background="#fff"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.crescendo.lldm.crescendo.A_Login">

    <RelativeLayout
        android:id="@+id/rl_one_login"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <View
            android:id="@+id/v_one_login"
            android:background="@drawable/gradient_background_one"
            android:layout_width="match_parent"
            android:layout_height="300dp" />

        <RelativeLayout
            android:layout_marginTop="90dp"
            android:id="@+id/rl_two_login"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:textStyle="bold"
                android:id="@+id/tv_one_login"
                android:textSize="32sp"
                android:textAlignment="center"
                android:textColor="@color/colorWhite"
                android:text="C R E S C E N D O"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:layout_below="@+id/tv_one_login"
                android:textSize="15sp"
                android:textAlignment="center"
                android:textColor="@color/colorWhite"
                android:text="FOR THE USA MONUMENTAL CHOIR"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </RelativeLayout>

    </RelativeLayout>

    <android.support.v7.widget.CardView
        app:cardUseCompatPadding="false"
        app:cardPreventCornerOverlap="false"
        android:id="@+id/cv_one_login"
        app:cardBackgroundColor="#fcfcfc"
        android:layout_marginTop="240dp"
        card_view:cardElevation="10dp"
        app:cardCornerRadius="10dp"
        android:elevation="10dp"
        android:layout_centerHorizontal="true"
        android:layout_width="360dp"
        android:layout_height="280dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"> …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-xml android-cardview

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