好像我在使用
时遇到错误@颜色/背景下, @ color / primary_dark ,以及 的 @绘制/ source_but 即可。
Error:(32, 33) No resource found that matches the given name (at 'background' with value '@color/background').
Error:(44, 36) No resource found that matches the given name (at 'textColor' with value '@color/primary_dark').
Error:(121, 33) No resource found that matches the given name (at 'background' with value '@drawable/source_but').
我在源代码中创建了一个表单 https://developer.android.com/training/displaying-bitmaps/index.html
所以基本上我尝试将文本框和其他对象放入:
布局文件夹下的image_detail_pager.xml。
以下是我尝试放置对象的方法:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background"
android:orientation="vertical"
tools:context="com.chalkstreet.learnandroid.main.Form">
<TextView
android:id="@+id/textViewHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:padding="10dp"
android:text="Fill the form and press the button to see the captured data."
android:textColor="@color/primary_dark"
android:textSize="16sp" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:ems="10"
android:hint="Name"
android:inputType="textPersonName"
android:textColor="#000000"
android:textColorHint="#f1434343" />
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:ems="10"
android:hint="Email"
android:inputType="textEmailAddress"
android:textColor="#000000"
android:textColorHint="#f1434343" />
<EditText
android:id="@+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
android:textColor="#000000"
android:textColorHint="#f1434343" />
<EditText
android:id="@+id/editText4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:ems="10"
android:hint="Phone"
android:inputType="phone"
android:textColor="#000000"
android:textColorHint="#f1434343" />
<Button
android:id="@+id/button_submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="Submit" />
</LinearLayout>
<Button
android:id="@+id/buttonSrc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/source_but"
android:text="VIEW SOURCE CODE FOR ACTIVITY" />
</RelativeLayout>
............................................... ..........................
我已经使用source_but.jpg更新了drawable,选择了我自己的图像。我更新了colors.xml。 现在我有一个不同的错误!这里似乎有些不一致。
Error:(34, 24) No resource found that matches the given name
(at 'label'
with value '@string/title_activity_form').
DisplayingBitmaps/Application/build/
intermediates/manifests/full/debug/AndroidManifest.xml
Error:Execution failed for task
':Application:processDebugResources'.
> com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException:
Process 'command 'Android/Sdk/build-tools/23.0.3/aapt''
finished with non-zero exit value 1
............................................... ........................
好的,我更新了Strings.xml,这是我最后的错误:
这是我的Form.java
public class Form extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_form);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//Initialize buttons and Edit Texts for form
Button btnSubmit = (Button) findViewById(R.id.button_submit);
Button btnSrc = (Button) findViewById(R.id.buttonSrc);
final EditText name = (EditText) findViewById(R.id.editText1);
final EditText email = (EditText) findViewById(R.id.editText2);
final EditText phone = (EditText) findViewById(R.id.editText4);
//Listener on Submit button
btnSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent sender = new Intent(Form.this, com.chalkstreet.learnandroid.main.Display.class);
Bundle b1 = new Bundle(); //Bundle to wrap all data
b1.putString("name", name.getText().toString()); //Adding data to bundle
b1.putString("email", email.getText().toString());
b1.putString("phone", phone.getText().toString());
sender.putExtras(b1); //putExtras method to send the bundle
startActivity(sender);
Form.this.finish(); //Finish form activity to remove it from stack
}
});
//Listener on source button
btnSrc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent j = new Intent(Form.this, MainSource.class);
startActivity(j);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
Form.this.finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}
以下是它给我的错误:
Error:(18, 32) error: cannot find symbol variable activity_form
Error:(33, 88) error: package com.chalkstreet.learnandroid.main does not exist
Error:(48, 50) error: cannot find symbol class MainSource
Error:(57, 41) error: cannot find symbol variable menu_main
答案 0 :(得分:1)
在colors.xml
文件中,您需要定义:
<color name="background">#FF0000</color>
<color name="primary_dark">#00FF00</color>
(使用您想要的颜色更改值)
然后,您需要将文件source_but
添加到drawable
文件夹中
如果是图像,只需将其移动到那里。