在这里他们写道:
要将样式定义应用为主题,必须将样式应用于Android清单中的活动或应用程序.执行此操作时,活动或应用程序中的每个视图都将应用它支持的每个属性.例如,如果将前面示例中的CodeFont样式应用于Activity,则所有支持文本样式属性的View元素都将应用它们.
因此,当我将TextColor设置为Red时,所有带文本的元素都会变为红色吗?CSS样式表中是否有强大的说明符?我只看到styles(style="@style/CodeFont")的概念是切实可行的.
我正在使用Android MOB,我想使用不同尺寸的横幅,特别是对于更大的屏幕尺寸.我正在使用XML代码这样做.有没有办法可以使用XML来使其工作?我想使用XML,所以我可以把它作为我的样式的标准部分,用于每种屏幕尺寸.谢谢!
示例XML代码:
<com.google.ads.AdView android:id="@+id/adView"
ads:loadAdOnCreate="true" ads:adSize="BANNER"
ads:adUnitId="@string/admob_unit_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" ></com.google.ads.AdView>
Run Code Online (Sandbox Code Playgroud) 关注问题:Android上视图背景颜色的动画更改我试图通过TransitionDrawable资源使TextView在两个背景之间淡入淡出.我的转换xml文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/gray_bar" />
<item android:drawable="@drawable/green_bar" />
</transition>
Run Code Online (Sandbox Code Playgroud)
我尝试通过以下方式将其设置为运行时的背景:
TextView answerBox = (TextView) findViewById(R.id.answerBox);
answerBox.setBackgroundResource(R.drawable.correct_transition);
TransitionDrawable transition = (TransitionDrawable) answerBox.getBackground();
transition.startTransition(1500);
Run Code Online (Sandbox Code Playgroud)
结果是textview转换成:
对此:

当整个灰色条应该变成绿色条.
两者都是9补丁png图像.这些是原件:

我的猜测是绿色条填满了灰色条内的文字空间,但我不知道为什么.有线索吗?尽管出现了所包含的图像,灰色的也看起来比它应该大得多,但是在转换之前,期间或之后不会改变大小.这可能是9补丁图像的问题,因为我已经测试了正常图像,并且过渡效果很好.
谢谢你的帮助!
有没有一种方法来设置并开始xml animation-list作为一个xml属性?我可以通过以下方式以编程方式设置和启动它:
ImageView img = (ImageView) findViewById(R.id.loadingImageView);
img.setBackgroundResource(R.drawable.loading_animation);
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
frameAnimation.start();
Run Code Online (Sandbox Code Playgroud)
动画列表是:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
//...
android:oneshot="false" >
<item
android:drawable="@drawable/loading_anim_frame_one"
android:duration="50"/>
<item
android:drawable="@drawable/loading_anim_frame_two"
android:duration="50"/>
Run Code Online (Sandbox Code Playgroud)
等等.
有没有办法xml只用标记来做这个,即没有java代码?
如果没有,是否有办法至少将其设置为xml属性,然后以编程方式启动它?
我不能使用单个drawable的旋转,因为动画按顺序包含几个drawable.
我有以下xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
<corners android:radius="10dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,它只是一个带圆角的形状.我将它用于活动布局中的背景,如下所示:
android:background="@drawable/rounded_corners"
Run Code Online (Sandbox Code Playgroud)
文件中的形状当前设置为白色.在不同的布局中,我需要不同的颜色.我是否需要为每种颜色创建不同形状的xml文件?我需要一种方法来在布局中指定要发送到背景的颜色,这样我就可以使用相同的xml来获得我想要的任何颜色.
谢谢.
我有一个简单的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
但即使我填写了fill_parent,我的TextView也没有占用所有的宽度.如何使用完整尺寸而不仅仅是内容的大小?
android textview android-layout android-linearlayout android-xml
我有一个使用以下XML布局的Fragment:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/card"
android:clickable="true"
android:onClick="editActions"
android:orientation="vertical" >
<TextView
android:id="@+id/title"
style="@style/CardTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:duplicateParentState="true"
android:text="@string/title_workstation" />
<Button
android:id="@+id/factory_button_edit"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:duplicateParentState="true"
android:text="@string/label_edit" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
如您所见,我有一个onClick参数设置LinearLayout.现在,TextView这个正确触发,并在所有空白区域.就在Button它上面没有调用我设置的onClick方法.
这是正常的吗?我该怎么做才能在所有地方调用onClick方法LinearLayout?
id资源可以在文件后面引用一个元素吗?
这里我有两个字段,一个用于用户名,另一个用于密码.我@+id/为密码字段创建了一个新的ID资源(带有语法),但是用户名字段在android:nextFocusDown字段中找不到它.我已经省略了布局xml中的其他字段,因为它们不相关.
在这种情况下,我如何申报身份证?
<EditText
android:id="@+id/login_username"
android:nextFocusDown="@id/login_password" />
<EditText
android:id="@+id/login_password"
android:nextFocusUp="@id/login_username"
android:nextFocusDown="@id/login_submit" />
Run Code Online (Sandbox Code Playgroud)
使用gradle构建,我收到的错误如下所示: Error:(41, 32) No resource found that matches the given name (at 'nextFocusDown' with value '@id/login_password').
我没有收到android:nextFocusUp="@id/login_username"字段错误,这使我相信你必须在使用之前声明id.
我的代码中也出现编译错误,因为没有R.java生成文件,很可能是因为它构建的资源也没有构建.
使用android中的所有花哨的构建工具,我很惊讶这是一个问题.这是一个已知的问题或期望的行为吗?
我有这样的布局:
<LinearLayout
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginEnd="8dp"
android:gravity="start|center_vertical"
android:orientation="horizontal"
android:layout_weight="0.25">
<ImageView
android:layout_width="wrap_content"
android:layout_height="20dp"
android:background="@drawable/reply_icon"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我正在尝试让ImageView适合它的高度(20dp)并自动调整宽度(同时保持其宽高比),然而,它看起来像这样拉伸:

我怎样才能解决这个问题?
如果EditText中文本的长度太长,则在文本中添加空格时,空格后的内容将被换行。例如,我有60个1,没有空格或换行符,并假设每行可以包含20 1,EditText将显示如下
11111111111111111111
11111111111111111111
11111111111111111111
Run Code Online (Sandbox Code Playgroud)
但是如果我在其中添加空间,它将像这样
11111111111111111111
1
11111111111111111111
1111111111111111111
Run Code Online (Sandbox Code Playgroud)
我在第二行的第一行之后添加了空格,在第一行被包装后添加了另外一个空格。我所期望的是
11111111111111111111
1 111111111111111111
11111111111111111111
1
Run Code Online (Sandbox Code Playgroud)
有什么办法吗?
编辑:
我正在尝试编写文本编辑器,因此我希望EditText是多行的。
我的代码是:
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="8dp"
android:layout_marginTop="4dp"
android:layout_marginRight="8dp"
android:inputType="textMultiLine"
android:gravity="start|top"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent" />
Run Code Online (Sandbox Code Playgroud)