Android DoneDiscard活动-无法设置内容布局
我使用Roman Nurik提供的这个类 但我无法更改我想要的Edittext字段的内容布局Android DoneDiscard活动-无法设置内容布局,android,android-layout,android-activity,Android,Android Layout,Android Activity,我使用Roman Nurik提供的这个类 但我无法更改我想要的Edittext字段的内容布局 public class AddActivity extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SystemBarTintManager tintManager = new SystemBarTintManager(thi
public class AddActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
tintManager.setStatusBarTintResource(R.color.black);
// Inflate a "Done/Discard" custom action bar view.
LayoutInflater inflater = (LayoutInflater) getActionBar().getThemedContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
final View customActionBarView = inflater.inflate(
R.layout.actionbar_custom_view_done_discard, null);
customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
customActionBarView.findViewById(R.id.actionbar_discard).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
// "Discard"
finish(); // TODO: don't just finish()!
}
});
// Show the custom action bar view and hide the normal Home icon and title.
final ActionBar actionBar = getActionBar();
actionBar.setDisplayOptions(
ActionBar.DISPLAY_SHOW_CUSTOM,
ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME
| ActionBar.DISPLAY_SHOW_TITLE);
actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
}
这是我要设置的布局:
<?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:orientation="vertical"
android:id="@+id/add_layout"
>
<EditText
android:id="@+id/title_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginTop="21dp"
android:ems="10"
android:hint="@string/add_hint_title"
android:inputType="text" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/info_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginTop="21dp"
android:ems="10"
android:hint="@string/add_hint_info"
android:inputType="textMultiLine" />
如果我尝试使用setContentViewR.layout.add_layout,它会将布局设置到操作栏中。有人知道如何在此活动中正确设置布局吗?您可以调用setContentView。。。直接在调用super.onCreate之后…:
或者您可以尝试以下方法:
inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.add_layout, null);
setContentView(v);
是的,谢谢!使用setContentView时,它不起作用,但使用第二种方式!
inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.add_layout, null);
setContentView(v);