我有一个应用程序,当单击一个按钮时,它会更改内容视图,但是当我按下后退按钮时,它会关闭活动.如何更改后退按钮的功能.在这种情况下,它将是后退按钮再次更改布局.
谢谢
我正在Android应用程序的登录页面上工作.
如您所知,应用程序必须检查用户名和密码是否有效,然后授予用户访问该应用程序的权限.
我使用了以下代码:
...
EditText un = (EditText) findViewById(R.id.username1);
EditText pw = (EditText) findViewById(R.id.password1);
String u = un.getText().toString();
String p = pw.getText().toString();
String myUser = "user1";
String myPass = "pass1";
//////// Now on the click of the Login Button:
public void onClickL (View view){
if ( (u == myUser) && (p == myPass)) /////// move to a new activity
else ///////Display a warning message: Try again
}
Run Code Online (Sandbox Code Playgroud)
我在两个editText字段中输入了正确的字符串,但是我总是收到警告消息.我不明白它有什么问题.
请帮忙 :)
我想要一个概念级别的方法,为什么我们在不同方面使用线性,相对,框架和绝对布局.我理解的是
1.LinearLayout - 用于逐个放置不同的控件,也可以是垂直和水平方向
2.RelativeLayout - 相对于其他控件放置控件
3.FrameLayout -Placeholder在屏幕上,您可以用来在一个视图中显示.
4.AbsoluteLayout -Place控制其子项的确切位置
5.TableLayout-将视图放入行和列
我需要专家的建议和需要进一步了解的布局既为Android设备和平板电脑.
提前致谢!!
我使用下面的代码来创建带有复选框的对话框:
创建:
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
LayoutInflater adbInflater = LayoutInflater.from(getContext());
LinearLayout eulaLayout = (LinearLayout) adbInflater.inflate(R.layout.checkbox, null);
dontShowAgain = (CheckBox)eulaLayout.findViewById(R.id.skip);
Run Code Online (Sandbox Code Playgroud)
checbox.xml的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root" android:orientation="horizontal"
android:layout_height="fill_parent"
android:padding="10dp">
<CheckBox
android:text="Do not show again"
android:id="@+id/skip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
</CheckBox>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我正在尝试实现一个Android应用程序,其中包含用户可以进行测验的部分.由于我是Android应用程序开发的新手,我想在布局方面有一些关于如何实现测验部分的建议
我有一组问题,每个问题都有各自的答案选择,我可以从我的API中检索.
执行此操作的最佳且易于实施的方法是什么?我需要逐页显示每个问题(Q1 - > Q2 - > ...).
我是否会生成一组片段?或者我是否以某种方式使用RecyclerView为每个问题生成每个页面?
任何指导将不胜感激,谢谢!
在我的活动中,我定义了3个textView控件.所有那些textView出现在另一个旁边 - 我需要做一些他们总是在相同大小的东西.假设第一个textView控件是小时,第二个textView控件是分钟,第三个textView控件是秒.
所以我想在全屏显示它们,所有textView控件都需要大小相同.
怎么做 ?
我想要搜索图标下方的搜索文本。搜索图标+文本组应位于屏幕中央。
我想要什么:____________屏幕实际是什么样子:
注意:我使用线性布局,因为我需要直接在下面的列表视图。它将用于搜索栏。对于那些建议使用 TextView 的人android:drawableTop,我尝试过,但图像太小(即使我将图像设置为 500px),而在图像视图中将图像设置为“100dpx100dp”时也是如此。
代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
app:srcCompat="@drawable/ic_search_gray_500px" />
<TextView
android:id="@+id/searchTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/search_hint"
android:layout_gravity="center_horizontal"
tools:layout_editor_absoluteX="130dp"
tools:text="@string/search_hint" />
</android.support.constraint.ConstraintLayout>
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
android textview imageview android-layout android-linearlayout
有人可以告诉我,如何在 AndroidStudio 中的 editText 中添加边框吗?
例如 editText 中的正方形。
我正在设计一个Android应用程序,我不需要创建任何布局xml文件,而是创建Java代码本身.我试着用这种方式: -
public class MainActivity extends Activity{
TextView tb;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().getDecorView().setBackgroundResource(R.drawable.ch);
}
}
Run Code Online (Sandbox Code Playgroud) android ×10
android-layout ×10
java ×3
xml ×3
if-statement ×1
imageview ×1
layout ×1
textview ×1