我想在android中创建文本编辑器并将其设置为主要活动 以下是我的截图
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="@+id/popup"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/background"
android:alpha="0.92">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Format your Text Style Here"
android:padding="10dp"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/popupMainText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_weight="0.03"
android:background="#fff"
android:gravity="center"
android:text="This is a simple popup"
android:textSize="25sp" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="Font Size"
android:textSize="20sp" />
<GridLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.14"
android:columnCount="4"
android:rowCount="5">
<Button
android:id="@+id/font1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="0"
android:text="Font 1" />
<Button
android:id="@+id/font2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="0"
android:text="Font 2" />
<Button
android:id ="@+id/colorRed"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/button_red_round"
android:layout_column="0"
android:layout_row="2"
android:layout_margin="5dp"
android:padding="15dp"
/>
</GridLayout>
<Button
android:id="@+id/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:text="Close" />
</LinearLayout>
button_red_round.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/red_id">
<shape android:shape="oval">
<stroke android:color="#ffffff" android:width="5dp" />
<solid android:color="#ff0000"/>
<size android:width="30dp" android:height="30dp"/>
</shape>
</item>
</selector>
MainActivity.java
此代码使我的应用程序崩溃
colorRed.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { popupMainText.setBackground(colorRed.getResources().getDrawable(R.drawable.button_red_round));
}
});
我希望按钮点击事件为预览和主要活动设置颜色 但是在事件应用于主要活动后我的申请无法打开