前提・実現したいこと
Android Studioで1つのレイアウトxmlに配置した複数のTextViewのプロパティに同じstyleを指定したいと思っています。
発生している問題・エラーメッセージ
[アプリ名]は停止しました。
と表示されます。
1つのxmlを複数のビューに適用することはできないのでしょうか。
該当のソースコード
●activity_main.xml
<TextView
style="@style/text"
android:id="@+id/text1"
android:text="テキスト1"/>
<TextView style="@style/text" android:id="@+id/text2" android:text="テキスト2"/>
●styles.xml
<resources>
<style name="text">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">#000000</item>
<item name="android:textColor">#ffffff</item>
<item name="android:textSize">24sp</item>
<item name="android:gravity">center</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingBottom">5dp</item>
<item name="android:layout_marginTop">5dp</item>
<item name="android:layout_marginBottom">5dp</item>
<item name="android:layout_marginLeft">20dp</item>
<item name="android:layout_marginRight">20dp</item>
</style>
</resources>
試したこと
以下のように、styleは使わずbackgroundに設定しても同様に落ちてしまいます。
●activity_main.xml
<TextView
android:background="@drawable/text"
android:text="テキスト1"/>
●text.xml
<?xml version="1.0" encoding="utf-8"?><shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#000000"/>
<corners android:radius="5dp"/>
</shape>
回答1件
あなたの回答
tips
プレビュー