我正在使用这样的代码在我的xml文件中创建一个三个EditText.
<EditText
android:id="@+id/name_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/profile_image_view_layout"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:ems="15"
android:hint="@string/name_field"
android:inputType="text" />
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,它在我的设备中看起来像这样.

但我想看看没有使用任何背景图像.

那怎么办呢?任何想法或建议都会有所帮助.
我有一个EditText和一个Button.点击按钮我想打开EditText键盘并同时请求重点EditText,以便用户直接开始键入键盘和文本出现在EditText.但在我的情况下,当我单击按钮时,它会打开键盘,但它不会将焦点设置在EditText,因为用户必须EditText再次单击它才能在其上书写.问题是什么 任何帮助或建议.
代码单击按钮
m_SearchEditText.requestFocus();
InputMethodManager inputMethodManager=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInputFromWindow(m_SearchEditText.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
Run Code Online (Sandbox Code Playgroud) 我有Button,点击,显示一个Dialog.一切都像魅力,但如果我双击按钮或快速单击按钮,Dialog打开两到三次.我必须单击后退按钮两次或三次才能解除Dialog.
我已经在SO上搜索了相关问题,但大多数答案建议禁用按钮或使用变量并将其设置为true和false,这不是我的要求.
如果有人知道如何解决这个问题,请帮助我.
我用的代码
// Delete item on click of delete button
holder.butDelete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Dialog passwordDialog = new Dialog(SettingsActivity.this);
passwordDialog.show();
}
});
Run Code Online (Sandbox Code Playgroud) 我有一个背景图像设置为ImageView,现在我想改变图像的不透明度,因为我写这个代码来改变ImageView的不透明度,但是当我这样做它从图像视图中删除背景图像,所以我的问题是如何在不删除背景图像的情况下更改ImageView的不透明度.
我使用的代码是:
ImageView imageView = (ImageView) findViewById(R.id.image_view);
imageView.setBackgroundResource(R.drawable.theme1_page_header); // Set background image
int opacity = 100; // from 0 to 255
imageView.setBackgroundColor(opacity * 0x1000000); // change opacity of image
Run Code Online (Sandbox Code Playgroud) 我有Button和TextView.最初单击按钮i增加计数值并显示在TextView中.我以前用过的代码是.
buttonDayPlus.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
count = count + 1;
textView.setText(Integer.toString(count));
}
}
Run Code Online (Sandbox Code Playgroud)
但现在我想要的是如果用户按下按钮,然后我想一个接一个递增值并显示增量值,textView并且一旦用户向上移动他的手......最终的增量值显示在textView.所以,如果有人知道帮我解决这个问题
我使用未记录的API来为Android OS 2.2添加日历事件.现在Android OS 4已经出局,我自然使用的API不起作用!我查看了关于14级日历api的Android SDK,但是我无法在我使用Android OS 2.2创建的项目中找到如何使用它的线索.因为当我CalendarContract在我的项目中使用类时,它显示错误.所以我无法在我使用Android OS 2.2创建的项目中找到线索以及如何使用此类的线索.
如果有人要分享任何样品或样品链接,请告诉我.
日历Api类
public abstract class CalendarAPI
{
private static CalendarAPI api;
public static CalendarAPI getAPI()
{
String apiClass;
if (Integer.parseInt(Build.VERSION.SDK) > Build.VERSION_CODES.FROYO) {
apiClass = "com.example.calendar.CycleManagerSDK8 ";
} else {
apiClass = "com.example.calendar.CycleManagerSDK14 ";
}
try
{
Class<? extends CalendarAPI> realClass = Class.forName(apiClass).asSubclass(CalendarAPI.class);
api = realClass.newInstance();
}
catch (Exception e)
{
throw new IllegalStateException(e);
}
return api;
}
public abstract boolean setAlertOnDevice(Context c) ;
}
Run Code Online (Sandbox Code Playgroud)
SDKVersion 8 - …
在android 4的推出之后,CalendarContract类被引入在设备日历中写入事件.但是,如果我使用API级别8创建了我的应用程序,现在我想CalendarContract在使用API级别8完成的项目中使用此类,因为在API级别8中我使用未记录的API在设备日历中编写事件并且此代码不会为Android 4工作.所以有可能CalendarContract在我的项目中使用类而不更改清单文件中的sdk版本,因为如果我将sdk版本更改为14然后它允许我使用CalendarContract类,我可以通过它来解决android的问题但是在这样做的时候我的应用程序没有开始在api 8 -13中运行,而我不想做,因为我的应用程序在市场上运行.那么有没有办法解决这个问题.请举个例子解释我
我创建了一个示例绘图应用程序,用户可以在其中使用宽度可变的笔画进行绘制。到目前为止,具有可变笔划的绘制路径都可以使用,但是绘制的线条并不平滑。我用来实现的代码如下所示。
过去两天来,我一直无法解决这个问题,请帮我解决。
使用可变笔触宽度绘制路径的代码
public class FingerPaint extends GraphicsActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new MyView(this));
}
public void colorChanged(int color) {
}
public class MyView extends View {
private static final float STROKE_WIDTH = 5f;
private Paint paint = new Paint();
private Path mPath = new Path();
ArrayList<Path> mPaths = new ArrayList<Path>();
ArrayList<Integer> mStrokes = new ArrayList<Integer>();
private float lastTouchX;
private float lastTouchY;
private final RectF dirtyRect = new RectF();
private int lastStroke = -1;
int variableWidthDelta …Run Code Online (Sandbox Code Playgroud) 我有两个Calendar Instance变量,一个是全局声明,另一个是本地声明.现在假设我将一个日历实例分配给另一个日历实例
Calendar m_CalGlobally = Calendar.getInstance();
Calendar calLocally = m_CalGlobally;
Run Code Online (Sandbox Code Playgroud)
现在我的问题是,如果我在calLocally变量中进行任何更改,m_CalGlobally实例变量中会出现相同的更改,为什么会发生这种情况,以及分配它的方式是什么.
我使用以下代码从库中获取文件.我检索的文件是图像文件,视频文件或基于用户选择的音频文件.
现在我在列表视图中显示从库中检索的文件.但我无法区分用户选择的文件是图像文件(即.jpg/.png)或其视频文件或音频文件.
通过获取扩展并在if else条件中检查它可能我知道.但我想知道它有可能做到这一点
用于从Gallery获取图像的代码是
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(intent, GET_VIDEO_AUDIO);
fileTransferDialog.dismiss();
Run Code Online (Sandbox Code Playgroud) 我正在片段类中创建选项卡.现在我在片段类中显示两个选项卡.一切正常,标签显示正确.只有高速缓存,显示的选项卡只占屏幕宽度的一半,它不占用全屏宽度.
所以任何人都告诉我在我的代码中我需要改变什么才能实现这一目标
我的守则
tabsinfo_fragment.xml文件
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#EFEFEF" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</HorizontalScrollView>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<FrameLayout
android:id="@+id/tab_1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<FrameLayout
android:id="@+id/tab_2"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
</LinearLayout>
</TabHost>
Run Code Online (Sandbox Code Playgroud)
tab.xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="20dp"
android:background="@drawable/tab_selector">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="@drawable/tab_text_selector"
android:textIsSelectable="false" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
片段类中的代码
public class TabsInfoFragment extends Fragment implements OnTabChangeListener
{
private …Run Code Online (Sandbox Code Playgroud) 我知道这个问题在这里被多次询问,我会通过所有答案并尝试在我的代码中实现它,但结果是失败的.这就是为什么我发布了一个新问题来运行我的代码.每当我想触发listView.setOnItemClickListener(this)时,问题就很简单.它没有被解雇.我尝试了stackoverflow中给出的每个建议,但无法解决问题.
我使用的代码是
visitor_list_fragment.xml文件
<?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" >
<TextView
android:id="@+id/node_name_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:textIsSelectable="false"
android:textSize="20sp" />
<ListView
android:id="@+id/visitor_list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:cacheColorHint="#00000000"
android:dividerHeight="5dp"
android:listSelector="#00000000"
android:scrollingCache="true"
android:smoothScrollbar="true" >
</ListView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
visitor_list_item.xml文件
<?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="wrap_content"
android:background="@android:color/transparent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/photo_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:contentDescription="@string/image_name"
android:focusable="false" />
<TextView
android:id="@+id/profile_info_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:focusable="false"
android:textColor="@android:color/black"
android:textIsSelectable="false"
android:textSize="20sp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我调用onItemClickListener的代码
public class VisitorListFragment extends Fragment implements OnItemClickListener
{
private TextView m_NodeName;
private ListView m_VisitorListView; …Run Code Online (Sandbox Code Playgroud) 我已经使用以下行代码以Calendar实例显示的Instance Everything显示24小时格式的时间,但唯一的问题是在午夜12:00显示时间,它显示时间为24:00而不是显示00:00.为什么在我的代码中发生任何错误.
Calendar m_CalInstance = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("kk:mm");
String timeDisplay = formatter.format(m_CalInstance.getTime());
Run Code Online (Sandbox Code Playgroud)